I did some more digging today to see If I can pin down the exact reason:
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.

Changing above code to:

            for a_ctr in range(abs(requiredAmountOfSerials) - a_len):
                a_serial = MetaSerial(value=u'')
                self._serials.append(a_serial)

produces no warnings



-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to