Commit e0dcdefc authored by Aurélien Bompard's avatar Aurélien Bompard Committed by Barry Warsaw

Use the relationship cascade feature to delete key-values

parent 33a64ede
......@@ -68,7 +68,7 @@ class Pended(Model):
id = Column(Integer, primary_key=True)
token = Column(Unicode)
expiration_date = Column(DateTime)
key_values = relationship('PendedKeyValue')
key_values = relationship('PendedKeyValue', cascade="all, delete-orphan")
def __init__(self, token, expiration_date):
super(Pended, self).__init__()
......@@ -147,8 +147,6 @@ class Pendings:
if isinstance(value, dict) and '__encoding__' in value:
value = value['value'].encode(value['__encoding__'])
pendable[keyvalue.key] = value
if expunge:
if expunge:
return pendable
......@@ -158,12 +156,6 @@ class Pendings:
right_now = now()
for pending in store.query(Pended).all():
if pending.expiration_date < right_now:
# Find all PendedKeyValue entries that are associated with the
# pending object's ID.
q = store.query(PendedKeyValue).filter(
PendedKeyValue.pended_id ==
for keyvalue in q:
# Copyright (C) 2015 by the Free Software Foundation, Inc.
# This file is part of GNU Mailman.
# GNU Mailman is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
# You should have received a copy of the GNU General Public License along with
# GNU Mailman. If not, see <>.
"""Test pendings."""
__all__ = [
import unittest
from mailman.config import config
from import InvalidEmailAddressError
from mailman.interfaces.pending import (
IPendable, IPended, IPendedKeyValue, IPendings)
from mailman.model.pending import PendedKeyValue, Pended, Pendings
from mailman.testing.layers import ConfigLayer
from zope.component import getUtility
from zope.interface import implementer
class SimplePendable(dict):
class TestPendings(unittest.TestCase):
"""Test pendings."""
layer = ConfigLayer
def test_delete_key_values(self):
# Deleting a pending should delete its key-values
pendingdb = getUtility(IPendings)
subscription = SimplePendable(
address='[email protected]',
display_name='Anne Person',
token = pendingdb.add(subscription)
self.assertEqual(pendingdb.count, 1)
pendable = pendingdb.confirm(token)
self.assertEqual(pendingdb.count, 0)
self.assertEqual(, 0)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment