From 67315dbbeb781921c7eb530b996e1020ad84e91b Mon Sep 17 00:00:00 2001
From: Barry Warsaw
Date: Tue, 23 Sep 2014 08:58:38 -0400
Subject: Since we don't have migrations, we don't need the ITemporaryDatabase
stuff, nor do we need the TAG mechanism. We also don't need load_sql() or
load_migrations().
---
src/mailman/config/configure.zcml | 20 --------------------
src/mailman/database/base.py | 38 --------------------------------------
src/mailman/database/factory.py | 26 ++++----------------------
src/mailman/database/postgresql.py | 2 --
src/mailman/database/sqlite.py | 2 --
src/mailman/interfaces/database.py | 6 ------
6 files changed, 4 insertions(+), 90 deletions(-)
(limited to 'src')
diff --git a/src/mailman/config/configure.zcml b/src/mailman/config/configure.zcml
index f9b9cb093..24061f0f0 100644
--- a/src/mailman/config/configure.zcml
+++ b/src/mailman/config/configure.zcml
@@ -40,20 +40,6 @@
factory="mailman.model.requests.ListRequests"
/>
-
-
-
-
-
-
0:
os.close(fd)
-
-
-
-# Test suite adapter for ITemporaryDatabase.
-
-def _cleanup(self, tempdir):
- shutil.rmtree(tempdir)
-
-
-def make_temporary(database):
- """Adapts by monkey patching an existing SQLite IDatabase."""
- tempdir = tempfile.mkdtemp()
- url = 'sqlite:///' + os.path.join(tempdir, 'mailman.db')
- with configuration('database', url=url):
- database.initialize()
- database._cleanup = types.MethodType(
- partial(_cleanup, tempdir=tempdir),
- database)
- # bool column values in SQLite must be integers.
- database.FALSE = 0
- database.TRUE = 1
- return database
--
cgit v1.3.1
From ad7a26a4383fd9f0034e1e50d8f4207adb5aa9f3 Mon Sep 17 00:00:00 2001
From: Barry Warsaw
Date: Tue, 23 Sep 2014 09:30:43 -0400
Subject: Use a simpler UUID implementation. Fix a typo.
---
src/mailman/database/types.py | 46 ++++++++++++++++---------------------------
src/mailman/model/address.py | 2 +-
2 files changed, 18 insertions(+), 30 deletions(-)
(limited to 'src')
diff --git a/src/mailman/database/types.py b/src/mailman/database/types.py
index 380ce37dc..641e065ba 100644
--- a/src/mailman/database/types.py
+++ b/src/mailman/database/types.py
@@ -29,8 +29,7 @@ __all__ = [
import uuid
from sqlalchemy import Integer
-from sqlalchemy.dialects import postgresql
-from sqlalchemy.types import TypeDecorator, BINARY, CHAR
+from sqlalchemy.types import TypeDecorator, CHAR
@@ -59,45 +58,34 @@ class Enum(TypeDecorator):
class UUID(TypeDecorator):
- """Handle UUIds."""
+ """Platform-independent GUID type.
- impl = BINARY(16)
- python_type = uuid.UUID
+ Uses Postgresql's UUID type, otherwise uses
+ CHAR(32), storing as stringified hex values.
- def __init__(self, binary=True, native=True):
- self.binary = binary
- self.native = native
+ """
+ impl = CHAR
def load_dialect_impl(self, dialect):
- if dialect.name == 'postgresql' and self.native:
- # Use the native UUID type.
- return dialect.type_descriptor(postgresql.UUID())
+ if dialect.name == 'postgresql':
+ return dialect.type_descriptor(UUID())
else:
- # Fallback to either a BINARY or a CHAR.
- kind = self.impl if self.binary else CHAR(32)
- return dialect.type_descriptor(kind)
-
- @staticmethod
- def _coerce(value):
- if value and not isinstance(value, uuid.UUID):
- try:
- value = uuid.UUID(value)
- except (TypeError, ValueError):
- value = uuid.UUID(bytes=value)
- return value
+ return dialect.type_descriptor(CHAR(32))
def process_bind_param(self, value, dialect):
if value is None:
return value
- if not isinstance(value, uuid.UUID):
- value = self._coerce(value)
- if self.native and dialect.name == 'postgresql':
+ elif dialect.name == 'postgresql':
return str(value)
- return value.bytes if self.binary else value.hex
+ else:
+ if not isinstance(value, uuid.UUID):
+ return "%.32x" % uuid.UUID(value)
+ else:
+ # hexstring
+ return "%.32x" % value
def process_result_value(self, value, dialect):
if value is None:
return value
- if self.native and dialect.name == 'postgresql':
+ else:
return uuid.UUID(value)
- return uuid.UUID(bytes=value) if self.binary else uuid.UUID(value)
diff --git a/src/mailman/model/address.py b/src/mailman/model/address.py
index d078f28d5..20bd631f5 100644
--- a/src/mailman/model/address.py
+++ b/src/mailman/model/address.py
@@ -57,7 +57,7 @@ class Address(Model):
preferences_id = Column(Integer, ForeignKey('preferences.id'))
preferences = relationship(
- 'Preferences', backref=backref('Address', uselist=False))
+ 'Preferences', backref=backref('address', uselist=False))
def __init__(self, email, display_name):
super(Address, self).__init__()
--
cgit v1.3.1
From eef73255db608785a55c055cbbfb800603671ff6 Mon Sep 17 00:00:00 2001
From: Barry Warsaw
Date: Tue, 23 Sep 2014 09:47:26 -0400
Subject: Update some comments.
---
src/mailman/model/requests.py | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
(limited to 'src')
diff --git a/src/mailman/model/requests.py b/src/mailman/model/requests.py
index 335e1e002..7f996dded 100644
--- a/src/mailman/model/requests.py
+++ b/src/mailman/model/requests.py
@@ -105,6 +105,9 @@ class ListRequests:
data_hash = token
request = _Request(key, request_type, self.mailing_list, data_hash)
store.add(request)
+ # XXX The caller needs a valid id immediately, so flush the changes
+ # now to the SA transaction context. Otherwise .id would not be
+ # valid. Hopefully this has no unintended side-effects.
store.flush()
return request.id
@@ -148,7 +151,7 @@ class _Request(Model):
__tablename__ = 'request'
- id = Column(Integer, primary_key=True)# TODO: ???, default=AutoReload)
+ id = Column(Integer, primary_key=True)
key = Column(Unicode)
request_type = Column(Enum(RequestType))
data_hash = Column(LargeBinary)
--
cgit v1.3.1