Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow MapAttribute instances to be used as the RHS in expressions. #488

Merged
merged 1 commit into from Apr 5, 2018

Conversation

jpinner-lyft
Copy link
Contributor

@jpinner-lyft jpinner-lyft commented Apr 5, 2018

The expression classes assume that whenever an attribute appears in the right hand side argument that the resulting expression should use the attribute's path. That allows users to compare two attributes of an item or to update one attribute of the item based on another. For example:

>>> class MyModel(Model):
...     foo = UnicodeAttribute()
...     bar = UnicodeAttribute()
...
>>> MyModel.foo > MyModel.bar
foo > bar
>>> MyModel.foo.set(MyModel.bar)
foo = bar

However, the code failed to consider that some attribute classes, specifically MapAttribute and its subclasses, can sometime act as AttributeContainer objects depending on the context. When instantiated as an attribute container, the instance should behave as a Value in the right hand side of an expression:

>>> class MyMap(MapAttribute):
...     foo = UnicodeAttribute()
...
>>> class MyModel(Model):
...     my_map = MyMap()
...
>>> my_map_instance = MyMap(foo='bar')
>>> MyModel.my_map.set(my_map_instance)
my_map = {'M': {'foo': {'S': u'bar'}}}

@jpinner-lyft jpinner-lyft force-pushed the fix-map-attribute-values branch 3 times, most recently from ed7855d to c171bc0 Compare April 5, 2018 03:46
@jpinner-lyft jpinner-lyft force-pushed the fix-map-attribute-values branch 3 times, most recently from 8daba39 to 6c8e308 Compare April 5, 2018 14:56
@jpinner-lyft jpinner-lyft merged commit ae4bb6c into master Apr 5, 2018
@jpinner-lyft jpinner-lyft deleted the fix-map-attribute-values branch April 5, 2018 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants