ioxiocom / firedantic

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

Fix issues with indexes #69

Closed joakimnordling closed 2 months ago

joakimnordling commented 2 months ago

There were two issues with setting up indexes:

  1. An AttributeError was raised when setting up indexes if there's a model that have no indexes. If you set up indexes using the approach suggested in the README, i.e. models=get_all_subclasses(Model), and there's at least one sub-model that does not define __composite_indexes__ an AttributeError was raised. This PR fixes that by adding the default value None, so you don't need to manually define it for each sub-class or make your own intermediate base class.
  2. If you defined a prefix for the collections, the prefix was ignored when creating the indexes, i.e. you didn't get an index for the collection you were actually using, but for one with the same name minus the prefix.