Skip to content
This repository has been archived by the owner on May 13, 2020. It is now read-only.

Commit

Permalink
Found a bug with sub-class detection. In short, it is not working.
Browse files Browse the repository at this point in the history
It requires some thought.
  • Loading branch information
strichter committed Aug 11, 2013
1 parent 3749a52 commit 68b7dcd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/mongopersist/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,18 @@ In order to accomplish collection sharing, you simply create another class
that has the same ``_p_mongo_collection`` string as another (sub-classing will
ensure that).

So let's give Stephan an extended address now.
So let's give Stephan two extended addresses now.

>>> dm.root['stephan'].address2 = ExtendedAddress(
... 'Tettau', '01945', 'Germany')
>>> dm.root['stephan'].address2
<ExtendedAddress Tettau (01945) in Germany>

>>> dm.root['stephan'].address3 = ExtendedAddress(
... 'Arnsdorf', '01945', 'Germany')
>>> dm.root['stephan'].address3
<ExtendedAddress Arnsdorf (01945) in Germany>

>>> transaction.commit()

When loading the addresses, they should be of the right type:
Expand All @@ -387,6 +393,13 @@ When loading the addresses, they should be of the right type:
<ExtendedAddress Tettau (01945) in Germany>


XXX: BUG with detecting derived classes properly. So for now just specify the
collection explicitely.

# >>> dm.root['stephan'].address3
# <ExtendedAddress Arnsdorf (01945) in Germany>


Tricky Cases
------------

Expand Down
2 changes: 2 additions & 0 deletions src/mongopersist/datamanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ def _flush_objects(self):
# object just once.
written = []
for obj in self._registered_objects:
__traceback_info__ = obj
orig = obj
if getattr(obj, '_p_mongo_sub_object', False):
# Make sure we write the object representing a document in a
# collection and not a sub-object.
Expand Down
5 changes: 4 additions & 1 deletion src/mongopersist/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ def __init__(self, jar):

def get_collection_name(self, obj):
__traceback_info__ = obj
db_name = getattr(obj, '_p_mongo_database', self._jar.default_database)
db_name = getattr(
obj, '_p_mongo_database',
self._jar.default_database if self._jar else None)
try:
coll_name = obj._p_mongo_collection
except AttributeError:
Expand Down Expand Up @@ -267,6 +269,7 @@ def store(self, obj, ref_only=False):
# XXX: Handle newargs; see ZODB.serialize.ObjectWriter.serialize
# Go through each attribute and search for persistent references.
doc = self.get_state(obj.__getstate__())

if getattr(obj, '_p_mongo_store_type', False):
doc['_py_persistent_type'] = get_dotted_name(obj.__class__)

Expand Down

0 comments on commit 68b7dcd

Please sign in to comment.