Skip to content

Commit f680242

Browse files
authored
Fix model inheritance of version attribute (#819)
1 parent acbeb41 commit f680242

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/integration/model_integration_test.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"""
22
Integration tests for the model API
33
"""
4+
45
from datetime import datetime
6+
57
from pynamodb.models import Model
68
from pynamodb.indexes import GlobalSecondaryIndex, AllProjection, LocalSecondaryIndex
79
from pynamodb.attributes import (
@@ -102,3 +104,38 @@ class Meta:
102104

103105
print(query_obj.update([TestModel.view.add(1)], condition=TestModel.forum.exists()))
104106
TestModel.delete_table()
107+
108+
109+
110+
def test_can_inherit_version_attribute(ddb_url) -> None:
111+
112+
class TestModelA(Model):
113+
"""
114+
A model for testing
115+
"""
116+
117+
class Meta:
118+
region = 'us-east-1'
119+
table_name = 'pynamodb-ci-a'
120+
host = ddb_url
121+
122+
forum = UnicodeAttribute(hash_key=True)
123+
thread = UnicodeAttribute(range_key=True)
124+
scores = NumberAttribute()
125+
version = VersionAttribute()
126+
127+
class TestModelB(TestModelA):
128+
class Meta:
129+
region = 'us-east-1'
130+
table_name = 'pynamodb-ci-b'
131+
host = ddb_url
132+
133+
with pytest.raises(ValueError) as e:
134+
class TestModelC(TestModelA):
135+
class Meta:
136+
region = 'us-east-1'
137+
table_name = 'pynamodb-ci-c'
138+
host = ddb_url
139+
140+
version_invalid = VersionAttribute()
141+
assert str(e.value) == 'The model has more than one Version attribute: version, version_invalid'

0 commit comments

Comments
 (0)