ioxiocom / firedantic

Database models for Firestore using Pydantic base models.
BSD 3-Clause "New" or "Revised" License
43 stars 14 forks source link

Fix issue with TTL policies in set_up_composite_indexes_and_ttl_policies #70

Closed joakimnordling closed 2 months ago

joakimnordling commented 2 months ago

This PR fixes the issue that if you were using get_all_subclasses() to gather the models to pass into the async_set_up_composite_indexes_and_ttl_policies() or set_up_composite_indexes_and_ttl_policies() like suggested in the README, like this:

    await async_set_up_composite_indexes_and_ttl_policies(
        gcloud_project="my-project",
        models=get_all_subclasses(AsyncModel),
        client=FirestoreAdminAsyncClient(),
    )

the indexes were created but the TTL policies were not. The get_all_subclasses() method returns an iterator and the underlying set_up_composite_indexes used up the generator so that the call to the set_up_ttl_policies got an empty generator. This fixes it by simply converting it to a list before passing it to each of the underlying functions and updates the test to spot the issue.