I am building a media database using SA where the model basically maps

Medium --1:N--> Versions --1:N--> Files

My code for creating new Medium instances based on an import script basically is doing the following:

f = File(...)
v = Version()
v.files.append(f)
m = Medium()
m.versions.append(v)
session.save(m)

This works perfectly for the import however I have to deal with File orphans
(caused by some business logic of the media database).

To get rid of orphans I added relation(..., cascade='all, delete-orphan')
to the mapper definitions. However running the import with this change
causes the following error:


File "lib/python/mediendb/misc/import_medien.py", line 86, in import_medien
   TH(import_medium, fullname)
File "/local2/HRS2/HEAD.Zope28/HaufeCMS/Products/HaufeCMS/Transactions.py", line 29, in __call__
   return TH.__call__(self, f, *args, **kw)
File "/local2/HRS2/HEAD.Zope28/HaufeCMS/lib/python/Haufe/Transactions/TransactionHandler.py", line 94, in __call__
   else: tmgr.get().commit() # old: transaction.get().commit()
File "/local2/HRS2/mediendb-ajung/HaufeCMS/Base/lib/python/transaction/_transaction.py", line 390, in commit
   self._saveCommitishError() # This raises!
File "/local2/HRS2/mediendb-ajung/HaufeCMS/Base/lib/python/transaction/_transaction.py", line 388, in commit
   self._commitResources()
File "/local2/HRS2/mediendb-ajung/HaufeCMS/Base/lib/python/transaction/_transaction.py", line 433, in _commitResources
   rm.commit(self)
File "build/bdist.linux-x86_64/egg/z3c/sqlalchemy/base.py", line 151, in commit File "build/bdist.linux-i686/egg/sqlalchemy/orm/session.py", line 302, in flush File "build/bdist.linux-i686/egg/sqlalchemy/orm/unitofwork.py", line 200, in flush File "build/bdist.linux-i686/egg/sqlalchemy/orm/mapper.py", line 290, in _is_orphan FlushError: instance <z3c.sqlalchemy.mapper._mapped_files object at 0xb3610eac> is an unsaved, pending instance and is an orphan (is not attached to any parent '_mapped_versions' instance via that classes' 'files' attribute)

Why does this cascade rule causes this error?

Andreas

--
ZOPYX Ltd. & Co. KG - Charlottenstr. 37/1 - 72070 Tübingen - Germany
Web: www.zopyx.com - Email: [EMAIL PROTECTED] - Phone +49 - 7071 - 793376
Registergericht: Amtsgericht Stuttgart, Handelsregister A 381535
Geschäftsführer/Gesellschafter: ZOPYX Limited, Birmingham, UK
------------------------------------------------------------------------
E-Publishing, Python, Zope & Plone development, Consulting

Attachment: pgpJz2ilK4tra.pgp
Description: PGP signature

Reply via email to