FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Set start_values on model reload by dcbrandao · Pull Request #64 · google/python-spanner-orm · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
8 changes: 7 additions & 1 deletion spanner_orm/model.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,15 @@ def reload(self, transaction: spanner_transaction.Transaction = None
updated_object = self._metaclass.find(transaction, **self.id())
if updated_object is None:
return None
start_values = {}

for column in self._columns:
value = getattr(updated_object, column)
start_values[column] = copy.copy(value)
if column not in self._primary_keys:
setattr(self, column, getattr(updated_object, column))
setattr(self, column, value)

self.start_values = start_values
self._persisted = True
return self

Expand Down
1 change: 1 addition & 0 deletions spanner_orm/tests/model_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def test_reload_reloads(self, find):
find.return_value = models.SmallTestModel(updated_values)
model.reload()
self.assertEqual(model.value_1, updated_values['value_1'])
self.assertEqual(model.changes(), {})

@mock.patch('spanner_orm.model.ModelApi.create')
def test_save_creates(self, create):
Expand Down

Back | FazBrowse Home | New Git URL