On 12/09/2015 12:16 PM, Mike Bayer wrote:
> 
> 
> On 12/09/2015 12:04 PM, Pau Tallada wrote:
>> Hi,
>>
>> Following on the documentation
>> (http://docs.sqlalchemy.org/en/latest/orm/collections.html?highlight=collection_class#dictionary-collections)
>>
>> I seem to understand that attribute_mapped_should verify that the key
>> used is the same as the mapped attribute. And it does, but only in this
>> case:
>>
>> item = Item()
>> item.notes = {
>>             '*CCC*': Note('AAA', 'atext'),
>>         }
>>
>> TypeError: Found incompatible key 'CCC' for value Note(id=None,
>> item_id=None, keyword=AAA, text=atext); this collection's keying
>> function requires a key of 'AAA' for this value.
>>
>> This fails as expected, but the following does not:
>>
>> item = Item()
>> item.notes['ccc'] = Note('aaa', 'atext')
>> print item.notes
>>
>> {'ccc': Note(id=None, item_id=None, keyword=aaa, text=atext)}
>>
>> item = Item()
>> item.notes.update({'ccc': Note('aaa', 'atext')})
>> print item.notes
>>
>> {'ccc': Note(id=None, item_id=None, keyword=aaa, text=atext)}
> 
> 
> this has to do with the internal implementation of the collection, in
> that when yo do a full assignment of a dictionary, it pulls out just the
> values from the dictionary, throws away the keys, and rewrites the
> values in using the keying function.   So your mismatched keys would be
> lost.    Whereas in the per-key-set, your key is still there.   It of
> course is all lost when you expire the collection and re-load.
> 
> If it were me I'd remove that assertion of keying and reorganize the
> collection system such that a full assignment of a dictionary doesn't
> involve blowing away the keys and re-fetching from the objects, as this
> is inefficient.   I will see if that's something I can do in five
> minutes (very unlikely) and if so I'll commit it to 1.1.

fixing up this general system of collection assignment has already been
logged months ago for 1.1 in
https://bitbucket.org/zzzeek/sqlalchemy/issues/3457/modernize-adapt_like_to_iterable
so this aspect of the change is added on.




> 
> 
>>
>>
>> I am thinking in implementing a custom collection class just to detect
>> those errors.
>> Am I missing something?
>>
>> Thanks in advance :)
>>
>> Pau.
>>
>> -- 
>> ----------------------------------
>> Pau Tallada Crespí
>> Dep. d'Astrofísica i Cosmologia
>> Port d'Informació Científica (PIC)
>> Tel: +34 93 586 8233
>> ----------------------------------
>>
>> -- 
>> 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
>> <mailto:sqlalchemy+unsubscr...@googlegroups.com>.
>> To post to this group, send email to sqlalchemy@googlegroups.com
>> <mailto:sqlalchemy@googlegroups.com>.
>> Visit this group at http://groups.google.com/group/sqlalchemy.
>> For more options, visit https://groups.google.com/d/optout.
> 

-- 
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 http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to