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

range_key_condition Doesn't work with TimestampMSAttribute #51

Open
Seluj78 opened this issue Sep 1, 2023 · 0 comments
Open

range_key_condition Doesn't work with TimestampMSAttribute #51

Seluj78 opened this issue Sep 1, 2023 · 0 comments

Comments

@Seluj78
Copy link

Seluj78 commented Sep 1, 2023

The table:

class EventTypeIndex(GlobalSecondaryIndex):
    class Meta:
        index_name = "EventTypeIndex"
        projection = AllProjection()

    event_type = UnicodeEnumAttribute(
        LogEventTypeEnum,
        hash_key=True,
        unknown_value=LogEventTypeEnum.GENERIC,
        default_for_new=LogEventTypeEnum.GENERIC,
    )


class Logs(Model):
    class Meta:
        table_name = "Logs"
        region = Session().get_config_variable("region")
        billing_mode = PAY_PER_REQUEST_BILLING_MODE

    user_id = NumberAttribute(hash_key=True)
    timestamp = TimestampMsAttribute(range_key=True)

    event_type = UnicodeEnumAttribute(
        LogEventTypeEnum, unknown_value=LogEventTypeEnum.GENERIC, default_for_new=LogEventTypeEnum.GENERIC
    )
    event_type_index = EventTypeIndex()
    content = UnicodeAttribute(null=True)

The crash :

[i for i in Logs.query(hash_key=9152, range_key_condition=Logs.timestamp.between(0, 9999999999999999))]
Traceback (most recent call last):
  File "/Users/seluj78/Applications/PyCharm Professional Edition.app/Contents/plugins/python/helpers/pydev/pydevconsole.py", line 364, in runcode
    coro = func()
           ^^^^^^
  File "<input>", line 1, in <module>
  File "/Users/seluj78/Projects/Datascientest/hub-backend/.venv/lib/python3.11/site-packages/pynamodb/attributes.py", line 176, in between
    return Path(self).between(lower, upper)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/seluj78/Projects/Datascientest/hub-backend/.venv/lib/python3.11/site-packages/pynamodb/expressions/operand.py", line 79, in between
    return Between(self, self._to_operand(lower), self._to_operand(upper))
                         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/seluj78/Projects/Datascientest/hub-backend/.venv/lib/python3.11/site-packages/pynamodb/expressions/operand.py", line 45, in _to_operand
    return Path(value) if isinstance(value, Attribute) else self._to_value(value)
                                                            ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/seluj78/Projects/Datascientest/hub-backend/.venv/lib/python3.11/site-packages/pynamodb/expressions/operand.py", line 328, in _to_value
    return Value(value, attribute=self.attribute)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/seluj78/Projects/Datascientest/hub-backend/.venv/lib/python3.11/site-packages/pynamodb/expressions/operand.py", line 200, in __init__
    (self.attr_type, value) = Value.__serialize(value, attribute)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/seluj78/Projects/Datascientest/hub-backend/.venv/lib/python3.11/site-packages/pynamodb/expressions/operand.py", line 221, in __serialize
    return attribute.attr_type, attribute.serialize(value)
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/seluj78/Projects/Datascientest/hub-backend/.venv/lib/python3.11/site-packages/pynamodb_attributes/timestamp.py", line 26, in serialize
    return str(int(value.timestamp() * self._multiplier))
                   ^^^^^^^^^^^^^^^
AttributeError: 'int' object has no attribute 'timestamp'
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

No branches or pull requests

1 participant