I tested with a unit test, and reduced the code above to bare minimum and not doing references to collections anymore.
def serials(self):
requiredAmountOfSerials = self.quantity
if requiredAmountOfSerials > len(self._serials):
a_len = len(self._serials)
for a_ctr in range(abs(requiredAmountOfSerials) - a_len):
self._serials.append( MetaSerial(value=u''))
Session.add(self) # MVO? is this needed?
Session.flush()
return self._serials
This above code gives a warning when you try to add for the first time something to self._serials collection. (so self._serials has no items)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/marcvano/dev/Acclivity/checkout4_env/Checkout/tests/models/serial_test.py", line 32, in testMakeRequest
self.assertEqual(len(op1.serials()), op1.allocated)
File "/Users/marcvano/dev/Acclivity/checkout4_env/Checkout/app/db/request.py", line 2161, in serials
self._serials.append(MetaSerial(value=u''))
File "build/bdist.macosx-10.6-intel/egg/sqlalchemy/orm/collections.py", line 1057, in append
item = __set(self, item, _sa_initiator)
File "build/bdist.macosx-10.6-intel/egg/sqlalchemy/orm/collections.py", line 1029, in __set
item = getattr(executor, 'fire_append_event')(item, _sa_initiator)
File "build/bdist.macosx-10.6-intel/egg/sqlalchemy/orm/collections.py", line 729, in fire_append_event
self._warn_invalidated()
File "build/bdist.macosx-10.6-intel/egg/sqlalchemy/orm/collections.py", line 600, in _warn_invalidated
util.warn("This collection has been invalidated.")
File "build/bdist.macosx-10.6-intel/egg/sqlalchemy/util/langhelpers.py", line 1036, in warn
warnings.warn(msg, exc.SAWarning, stacklevel=stacklevel)
SAWarning: This collection has been invalidated.