Skip to content

Commit

Permalink
Fix issue with TTL policies in set_up_composite_indexes_and_ttl_polic…
Browse files Browse the repository at this point in the history
…ies (#70)
  • Loading branch information
joakimnordling committed Jun 17, 2024
1 parent f7944bb commit 546f0c9
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

## [0.7.2] - 2024-06-17

### Fixed

- Ensure TTL policies are created by `async_set_up_composite_indexes_and_ttl_policies`
and `set_up_composite_indexes_and_ttl_policies` also when passing in the models as a
generator, for example when using `get_all_subclasses()`.

## [0.7.1] - 2024-06-14

### Fixed
Expand Down Expand Up @@ -230,7 +238,8 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Update README.md
- Update .gitignore

[unreleased]: https://github.com/ioxiocom/firedantic/compare/0.7.1...HEAD
[unreleased]: https://github.com/ioxiocom/firedantic/compare/0.7.2...HEAD
[0.7.2]: https://github.com/ioxiocom/firedantic/compare/0.7.1...0.7.2
[0.7.1]: https://github.com/ioxiocom/firedantic/compare/0.7.0...0.7.1
[0.7.0]: https://github.com/ioxiocom/firedantic/compare/0.6.0...0.7.0
[0.6.0]: https://github.com/ioxiocom/firedantic/compare/0.5.1...0.6.0
Expand Down
1 change: 1 addition & 0 deletions firedantic/_async/indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ async def set_up_composite_indexes_and_ttl_policies(
:param client: The Firestore admin client.
:return: List of operations that were launched.
"""
models = list(models)
ops = await set_up_composite_indexes(gcloud_project, models, database, client)
ops.extend(await set_up_ttl_policies(gcloud_project, models, database, client))
return ops
1 change: 1 addition & 0 deletions firedantic/_sync/indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def set_up_composite_indexes_and_ttl_policies(
:param client: The Firestore admin client.
:return: List of operations that were launched.
"""
models = list(models)
ops = set_up_composite_indexes(gcloud_project, models, database, client)
ops.extend(set_up_ttl_policies(gcloud_project, models, database, client))
return ops
8 changes: 6 additions & 2 deletions firedantic/tests/tests_async/test_indexes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
from unittest.mock import AsyncMock

from google.cloud.firestore import Query
Expand Down Expand Up @@ -89,12 +90,15 @@ class ModelWithIndexes(BaseModelWithIndexes):
collection_index(("name", Query.ASCENDING), ("age", Query.DESCENDING)),
)

__ttl_field__ = "expire"
expire: datetime

result = await async_set_up_composite_indexes_and_ttl_policies(
gcloud_project="proj",
models=[ModelWithIndexes],
models=(model for model in [ModelWithIndexes]), # Test with a generator
client=mock_admin_client,
)
assert len(result) == 1
assert len(result) == 2

call_list = mock_admin_client.create_index.call_args_list
assert len(call_list) == 1
Expand Down
8 changes: 6 additions & 2 deletions firedantic/tests/tests_sync/test_indexes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
from unittest.mock import Mock

from google.cloud.firestore import Query
Expand Down Expand Up @@ -86,12 +87,15 @@ class ModelWithIndexes(BaseModelWithIndexes):
collection_index(("name", Query.ASCENDING), ("age", Query.DESCENDING)),
)

__ttl_field__ = "expire"
expire: datetime

result = set_up_composite_indexes_and_ttl_policies(
gcloud_project="proj",
models=[ModelWithIndexes],
models=(model for model in [ModelWithIndexes]), # Test with a generator
client=mock_admin_client,
)
assert len(result) == 1
assert len(result) == 2

call_list = mock_admin_client.create_index.call_args_list
assert len(call_list) == 1
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "firedantic"
version = "0.7.1"
version = "0.7.2"
description = "Pydantic base models for Firestore"
authors = ["IOXIO Ltd"]
license = "BSD-3-Clause"
Expand Down

0 comments on commit 546f0c9

Please sign in to comment.