File tree Expand file tree Collapse file tree 3 files changed +18
-3
lines changed Expand file tree Collapse file tree 3 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -31,8 +31,6 @@ def __init__(
31
31
aws_secret_access_key : Optional [str ] = None ,
32
32
aws_session_token : Optional [str ] = None ,
33
33
) -> None :
34
- self ._hash_keyname = None
35
- self ._range_keyname = None
36
34
self .table_name = table_name
37
35
self .connection = Connection (region = region ,
38
36
host = host ,
Original file line number Diff line number Diff line change @@ -1009,7 +1009,9 @@ def _get_connection(cls) -> TableConnection:
1009
1009
cls .__module__ , cls .__name__ ,
1010
1010
),
1011
1011
)
1012
- if cls ._connection is None :
1012
+ # For now we just check that the connection exists and (in the case of model inheritance)
1013
+ # points to the same table. In the future we should update the connection if any of the attributes differ.
1014
+ if cls ._connection is None or cls ._connection .table_name != cls .Meta .table_name :
1013
1015
cls ._connection = TableConnection (cls .Meta .table_name ,
1014
1016
region = cls .Meta .region ,
1015
1017
host = cls .Meta .host ,
Original file line number Diff line number Diff line change @@ -3256,3 +3256,18 @@ class Meta:
3256
3256
class ChildModel (ParentModel ):
3257
3257
pass
3258
3258
self .assertEqual (ParentModel .Meta .table_name , ChildModel .Meta .table_name )
3259
+
3260
+ def test_connection_inheritance (self ):
3261
+ class Foo (Model ):
3262
+ class Meta :
3263
+ table_name = 'foo'
3264
+ class Bar (Foo ):
3265
+ class Meta :
3266
+ table_name = 'bar'
3267
+ class Baz (Foo ):
3268
+ pass
3269
+ assert Foo ._get_connection () is not Bar ._get_connection ()
3270
+ assert Foo ._get_connection () is Baz ._get_connection ()
3271
+ self .assertEqual (Foo ._get_connection ().table_name , Foo .Meta .table_name )
3272
+ self .assertEqual (Bar ._get_connection ().table_name , Bar .Meta .table_name )
3273
+ self .assertEqual (Baz ._get_connection ().table_name , Baz .Meta .table_name )
You can’t perform that action at this time.
0 commit comments