Skip to content

Commit

Permalink
TP2000 1650 commodities snapshot behaviour (#1379)
Browse files Browse the repository at this point in the history
Using CommodityCollectionLoader.load(effective_only=True) gives an error, because a filter is applied to a non existing field.
Added a small test showing the issue, and changed the code to fix it.

Requires migrations: No
Requires dependency updates: No
  • Loading branch information
Luisella21 authored Jan 28, 2025
1 parent eef617b commit 9030deb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ ENV/
env.bak/
docker-compose.override.yml
settings/envs/docker.override.env
.envrc

# Spyder project settings
.spyderproject
Expand Down
3 changes: 1 addition & 2 deletions commodities/models/dc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1600,8 +1600,7 @@ def _apply_filters(qs: TrackedModelQuerySet):
goods_sids = Subquery(goods_query.values("sid"))

indents_query = (
_apply_filters(GoodsNomenclatureIndent.objects)
.with_end_date()
_apply_filters(GoodsNomenclatureIndent.objects.with_end_date())
.filter(indented_goods_nomenclature__sid__in=goods_sids)
.annotate(goods_sid=F("indented_goods_nomenclature__sid"))
.order_by("transaction", "validity_start")
Expand Down
8 changes: 8 additions & 0 deletions commodities/tests/test_commodity_tree_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,11 @@ def test_get_dependent_measures_works_with_wonky_archived_measure(
assert wonky_archived_measure.generating_regulation == old_regulation
assert target_commodity in commodities_collection.commodities
assert target_commodity in target.commodities


def test_commodity_collection_loader(seed_database_with_indented_goods):
# Test that 'effective_only' does not crash the code
commodities_collection = CommodityCollectionLoader(prefix="2903").load(
effective_only=True,
)
assert len(commodities_collection.commodities) == 6

0 comments on commit 9030deb

Please sign in to comment.