Skip to content

Commit

Permalink
Exclude revision_id from the get_changes method (#759)
Browse files Browse the repository at this point in the history
* Exclude revision_id from get_changes

* line length fix

* test

* GH action python versions as strings
  • Loading branch information
roman-right committed Dec 3, 2023
1 parent 8a856ac commit c77114f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/github-actions-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ 3.7, 3.8, 3.9, 3.10.6, 3.11 ]
python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11" ]
mongodb-version: [ 4.4, 5.0 ]
pydantic-version: [ 1.10.12, 2.3 ]
runs-on: ubuntu-latest
Expand Down
8 changes: 7 additions & 1 deletion beanie/odm/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,13 @@ def _collect_updates(
@saved_state_needed
def get_changes(self) -> Dict[str, Any]:
return self._collect_updates(
self._saved_state, get_dict(self, to_db=True, keep_nulls=self.get_settings().keep_nulls) # type: ignore
self._saved_state, # type: ignore
get_dict(
self,
to_db=True,
keep_nulls=self.get_settings().keep_nulls,
exclude={"revision_id", "_previous_revision_id"},
),
)

@saved_state_needed
Expand Down
32 changes: 32 additions & 0 deletions tests/odm/test_state_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,3 +430,35 @@ async def test_replace_save_previous(self, saved_doc_previous):

assert saved_doc_previous.get_saved_state()["num_1"] == 100
assert saved_doc_previous.get_previous_saved_state()["num_1"] == 1

async def test_exclude_revision_id_and_previous_revision_id(
self, saved_doc_previous
):
saved_doc_previous.num_1 = 100
await saved_doc_previous.replace()

assert saved_doc_previous.get_saved_state()["num_1"] == 100
assert saved_doc_previous.get_previous_saved_state()["num_1"] == 1

assert (
saved_doc_previous.get_saved_state().get("revision_id") is None
)
assert (
saved_doc_previous.get_saved_state().get(
"previous_revision_id"
)
is None
)

assert (
saved_doc_previous.get_previous_saved_state().get(
"revision_id"
)
is None
)
assert (
saved_doc_previous.get_previous_saved_state().get(
"previous_revision_id"
)
is None
)

0 comments on commit c77114f

Please sign in to comment.