- changed status to duplicate
make Custom List Classes cleaner
Issue #563
resolved
Hi,
First, please consider I'm new to SQLAlchemy. I find the custom list classes pattern interesting, it can make a lot of use cases cleaner. However, there is an API problem: it modifies the __iter___ method from dict. It can lead to subtle bugs if one doesn't pay attention, especially if someone uses the object without knowing it is managed by the SQLAlchemy mapper.
What the "collection_class" option could do is see whether the custom class has a values() (or itervalues()), and use that one instead of iter it it exists. This means the user only has to add an append() method, without breaking the standard dict API (and, if he doesn't subclass dict, he just has to implement an itervalues() method instead of an iter() method).
Comments (1)
-
repo owner - Log in to comment
thanks for your comments. these ideas have already been in the queue for many months now underneath
#213, where I have also added a note about iter(dictionary) being able to return keys().the main work with
__iter__()
is that the rest of the ORM has to no longer call straight iteration on the collection since its behavior can change based on the underlying collection.