Skip to content

Commit 98d822d

Browse files
committed
Use ZODB new class_factory parameter to register class factory
1 parent 36cfb1a commit 98d822d

5 files changed

Lines changed: 11 additions & 35 deletions

File tree

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ https://github.com/zopefoundation/Zope/blob/5.x/CHANGES.rst.
1414

1515
- Update to newest compatible versions of dependencies.
1616

17+
- Use ZODB new ``class_factory`` parameter to fix registration of ZODB class
18+
factory sometimes not beeing effective.
19+
See `ZODB issue #420 <https://github.com/zopefoundation/ZODB/issues/420>`_.
20+
1721

1822
6.0 (2026-03-04)
1923
----------------

docs/locale/ja/LC_MESSAGES/operation.po

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,19 +1657,6 @@ msgid ""
16571657
"specify the connection class."
16581658
msgstr ""
16591659

1660-
#: ../../Schema
1661-
msgid ""
1662-
"class-factory (Zope2.Startup.datatypes.importable_name) (default: "
1663-
"Zope2.Startup.datatypes.simpleClassFactory)"
1664-
msgstr ""
1665-
1666-
#: ../../description:1
1667-
msgid ""
1668-
"Change the class factory function a database uses on a per-database basis"
1669-
" to support different class factory policy. Use a Python dotted-path name"
1670-
" to specify the class factory function."
1671-
msgstr ""
1672-
16731660
#: ../../Schema
16741661
msgid "container-class (string)"
16751662
msgstr ""

src/Zope2/App/startup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def startup():
7979
getattr(configuration, 'testinghome', None),
8080
configuration.instancehome,
8181
]
82+
from .ClassFactory import ClassFactory
8283
for location in custom_locations:
8384
if not location:
8485
continue
@@ -91,8 +92,10 @@ def startup():
9192
DB = module.DB
9293
databases.update(getattr(DB, 'databases', {}))
9394
DB.databases = databases
95+
DB.classFactory = ClassFactory
9496
else:
95-
DB = ZODB.DB(module.Storage, databases=databases)
97+
DB = ZODB.DB(module.Storage, databases=databases,
98+
class_factory=ClassFactory)
9699

97100
break
98101
else:
@@ -116,9 +119,6 @@ def startup():
116119
Zope2.DB = DB
117120
Zope2.opened.append(DB)
118121

119-
from . import ClassFactory
120-
DB.classFactory = ClassFactory.ClassFactory
121-
122122
# "Log on" as system user
123123
newSecurityManager(None, AccessControl.users.system)
124124

src/Zope2/Startup/datatypes.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,16 @@ class ZopeDatabase(ZODBDatabase):
135135

136136
def createDB(self, database_name, databases):
137137
self.config.database_name = database_name
138+
if self.config.class_factory is None:
139+
from Zope2.App.ClassFactory import ClassFactory
140+
self.config.class_factory = ClassFactory
138141
return ZODBDatabase.open(self, databases)
139142

140143
def open(self, database_name, databases):
141144
DB = self.createDB(database_name, databases)
142145
if self.config.connection_class:
143146
# set the connection class
144147
DB.klass = self.config.connection_class
145-
if self.config.class_factory is not None:
146-
DB.classFactory = self.config.class_factory
147148
return DB
148149

149150
def getName(self):
@@ -257,10 +258,3 @@ def getName(self, mount_path):
257258
if name is None:
258259
self._mountPathError(mount_path)
259260
return name
260-
261-
262-
def simpleClassFactory(jar, module, name, _silly=('__doc__',), _globals={}):
263-
"""Class factory.
264-
"""
265-
m = __import__(module, _globals, _globals, _silly)
266-
return getattr(m, name)

src/Zope2/Startup/wsgischema.xml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,6 @@
6161
</description>
6262
</key>
6363

64-
<key name="class-factory" datatype=".importable_name"
65-
default="Zope2.Startup.datatypes.simpleClassFactory">
66-
<description>
67-
Change the class factory function a database uses on a
68-
per-database basis to support different class factory policy.
69-
Use a Python dotted-path name to specify the class factory function.
70-
</description>
71-
</key>
72-
7364
<key name="container-class" datatype="string">
7465
<description>
7566
Change the container class a (mounted) database uses on a

0 commit comments

Comments
 (0)