You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my pynamodb model, I have an attribute, which can be an instance of one of the sub-classes of a polymorphic map attribute like:
class ParentClass(MapAttribute):
cls = DiscriminatorAttribute()
class ChildClass1(ParentClass, discriminator = cls.__name__):
filter_attr = UnicodeAttribute()
class ChildClass2(ParentClass, discriminator = cls.__name__):
other_attr = UnicodeAttribute()
class MyModel(Model):
...
attr = ParentClass()
If I define a filter condition on MyModel.attr.filter_attr like MyModel.attr.filter_attr == value, I get the run time error
def __getattr__(self, attr: str) -> _VT:
# This should only be called for "raw" (i.e. non-subclassed) MapAttribute instances.
# MapAttribute subclasses should access attributes via the Attribute descriptors.
if self.is_raw() and self._is_attribute_container():
try:
return self.attribute_values[attr]
except KeyError:
pass
> raise AttributeError("'{}' has no attribute '{}'".format(self.__class__.__name__, attr))
E AttributeError: 'ParentClass' has no attribute 'filter_attr'
which makes sense because attr is of type ParentClass, which only has cls attribute.
My question is, is there a way to define a filter on a nested attribute in a pynamodb model, where the nested attribute is an instance of a child class of a polymorphic MapAttribute parent class?
The text was updated successfully, but these errors were encountered:
I can't think of a good way to do this right now. You can probably go lower-level by doing something like MyModel.attr['filter_attr'] == {'S': 'foobar'}, which is not ideal syntax-wise (you lose the knowledge of filter_attr's type and end up performing serialization yourself),.
If I do MyModel.attr['filter_attr'] == value when ParentClass inherits MapAttribute, I get AttributeError: 'ParentClass' has no attribute 'filter_attr' again.
if ParentClass inherits DynamicMapAttribute, this seems to work though.
is there anything else I can try to make this work with MapAttribute?
Hello,
In my pynamodb model, I have an attribute, which can be an instance of one of the sub-classes of a polymorphic map attribute like:
If I define a filter condition on
MyModel.attr.filter_attr
likeMyModel.attr.filter_attr == value
, I get the run time errorwhich makes sense because
attr
is of typeParentClass
, which only hascls
attribute.My question is, is there a way to define a filter on a nested attribute in a pynamodb model, where the nested attribute is an instance of a child class of a polymorphic MapAttribute parent class?
The text was updated successfully, but these errors were encountered: