On Wed, Jun 28, 2017 at 12:02 AM, Andy Green <andrew.gr...@aao.gov.au>
wrote:

> Now, some investigating has revealed the following information:
> - commenting out the `__reduce__` function on OrderedList seems to make
> everything work correctly (including the unit tests on orderinglist.py).
> This function is definitely being called, though my code is not pickling
> the object (perhaps SQLAlchemy is calling this?)
>

you actually don't know the function is being called if removing it changes
behavior elsewhere, because lots of things in Python depend on
non-deterministic things like dictionary ordering, which is essentially
random, but can be seeded differently when other subtle things change, like
whether or not .pyc files are already present.   You should set
PYTHONHASHSEED=random in your environment, and to prove __reduce__ and the
internal _reconstitute aren't being called you can put an exception throw
or print statement in them.  SQLAlchemy does not call __reduce__ or do any
pickling, unless you run the one test in test_orderinglist that itself
tests pickling.


> - in the last frame of the above traceback, self._data() is a weakref, and
> the fact that it is returning None suggests the object (which I believe
> would be the instance of OrderingList in this case) has been deleted. I can
> only explain this if somehow the relationship list is being replaced,
> though I can find no indication this is true in my code.
>

unfortunately neither can I if you can't provide an MCVE (what you refer to
as an MWE :) ).


> - Simply replacing the collection_class with `list` makes the code work as
> expected
> - The unit tests for orderinglist (py.test test/ext/test_orderinglist.py)
> all pass.
>
> I'm out of time to debug this, and orderinglist doesn't provide quite what
> I need anyway (which is really more an order preserving dict such as
> OrderedDict), so I'm afraid I can't offer a lot more here. It seems to me
> that `ordering_list` is not actually working at all currently, but that the
> unit tests don't actually save and restore an object containing this
> relationship to a database, and hence it isn't being picked up. I suspect
> that `__reduce__` is being called, and it is inadvertently replacing the
> OrderingList created when the relationship is created, and hence the
> original object is being garbage collected and therefore the weakref
> mentioned above is void, causing the exception. Quick fix would be to
> simply not have a `__reduce__` function on OrderingList, but I'm afraid I
> don't understand enough about pickling to know if this would cause problems.
>

try the PYTHONHASHSEED=random variable, which is almost always how to smoke
out these kinds of bugs.


>
> Cheers,
> Andy
>
>
>
>
>
>
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
> description.
> ---
> 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 sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to