PynamoDB icon indicating copy to clipboard operation
PynamoDB copied to clipboard

Bug with Model init when having a hash or range key of 0

Open pior opened this issue 11 years ago • 2 comments

Given a Thread Project with a numerical key:

class Project(Model):
    class Meta:
        table_name = DB_TABLE_PREFIX + 'Device'

    project_id = NumberAttribute(hash_key=True)
In [58]: Project(0).project_id is None
Out[58]: True

In [59]: Project(project_id=0).project_id == 0
Out[59]: True

See https://github.com/jlafon/PynamoDB/blob/devel/pynamodb/models.py#L241

pior avatar Apr 06 '15 19:04 pior

There seems to be the same issue on the deserialization side :

In [70]: list(Project.scan())
Out[70]: [Project<1>, Project<null>]
In [73]: Project.get(0)
Out[73]: PostalApiTest_Device<null>

In [74]: Project.get(0).project_id is None
Out[74]: True

pior avatar Apr 06 '15 19:04 pior

I have the same issue for the numeric range key.

kyangmove avatar May 12 '15 01:05 kyangmove