Skip to content

fix(farmer_demo): assign FARM group type to farm demo data (#1120) - #322

Open
emjay0921 wants to merge 4 commits into
19.0from
fix/1120-farm-group-type
Open

fix(farmer_demo): assign FARM group type to farm demo data (#1120)#322
emjay0921 wants to merge 4 commits into
19.0from
fix/1120-farm-group-type

Conversation

@emjay0921

Copy link
Copy Markdown
Contributor

Why is this change needed?

The farmer demo data generator created farm groups with a blank Group Type (OP#1120). Farm groups should default to Farm, and cooperative container groups to Cooperative. Neither generator set group_type_id, and no farm code existed in the urn:openspp:vocab:group-type vocabulary (only cooperative was created at runtime).

How was the change implemented?

  • Added _ensure_farm_group_type() (mirrors the existing _ensure_cooperative_group_type()) to create a local farm group-type code via get_or_create_local — in both the story-farm wizard and the seeded-farm utility.
  • Set group_type_id = farm on every farm group created by both generators (story farms in _create_farm, and the ~730 seeded/volume farms).
  • Cooperative container groups keep group_type_id = cooperative; member farms stay Farm (a farm is still a farm inside a cooperative — only the container is a Cooperative).

New unit tests

  • test_1120_cooperative_container_typed_cooperative — the cooperative container is typed cooperative and its member farms are typed farm.
  • Added group_type_id.code == "farm" assertions to the seeded-farm generator test, the story-farm group test, and the _create_farm helper test.

Unit tests executed by the author

spp_farmer_registry_demo suite: 0 failed, 0 error(s) of 133 tests (fresh DB, --stop-after-init).

How to test manually

  1. Run the farmer demo data generator (with cooperatives enabled).
  2. Registry → Groups: open any farm group → Group Type = Farm; open a cooperative (e.g. Nueva Ecija Rice Cooperative) → Group Type = Cooperative.
  3. Confirm no farm group has a blank Group Type, and that cooperative member farms are still typed Farm.

Related links

https://projects.acn.fr/work_packages/1120

@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@codecov

codecov Bot commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.13%. Comparing base (8532fa4) to head (38d7a9a).

Files with missing lines Patch % Lines
...rmer_registry_demo/models/farmer_demo_generator.py 75.00% 3 Missing ⚠️
...rmer_registry_demo/models/seeded_farm_generator.py 76.92% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             19.0     #322      +/-   ##
==========================================
- Coverage   72.24%   67.13%   -5.11%     
==========================================
  Files         419      100     -319     
  Lines       29813     9814   -19999     
==========================================
- Hits        21539     6589   -14950     
+ Misses       8274     3225    -5049     
Flag Coverage Δ
spp_analytics ?
spp_api_v2_change_request ?
spp_api_v2_cycles ?
spp_api_v2_data ?
spp_api_v2_entitlements ?
spp_api_v2_gis ?
spp_api_v2_programs ?
spp_api_v2_service_points ?
spp_attachment_av_scan ?
spp_base_common 91.07% <ø> (ø)
spp_change_request_v2 ?
spp_claim_169 ?
spp_cr_type_assign_program ?
spp_dci ?
spp_dci_client ?
spp_dci_client_compliance ?
spp_dci_client_crvs ?
spp_dci_client_dr ?
spp_dci_demo ?
spp_drims ?
spp_drims_sl_demo ?
spp_farmer_registry_cr ?
spp_farmer_registry_demo 63.43% <76.00%> (+2.37%) ⬆️
spp_grm_cel ?
spp_key_management ?
spp_mis_demo_v2 ?
spp_oauth ?
spp_programs 65.27% <ø> (ø)
spp_registry 87.22% <ø> (+0.07%) ⬆️
spp_security 69.56% <ø> (ø)
spp_starter_sp_mis ?
spp_studio_change_requests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...rmer_registry_demo/models/farmer_demo_generator.py 53.60% <75.00%> (+3.45%) ⬆️
...rmer_registry_demo/models/seeded_farm_generator.py 82.07% <76.92%> (-0.16%) ⬇️

... and 320 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@emjay0921
emjay0921 marked this pull request as draft July 27, 2026 08:27
@emjay0921
emjay0921 marked this pull request as ready for review August 13, 2026 05:41

@gonzalesedwin1123 gonzalesedwin1123 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks — this one is in good shape. The fix is correct and well-scoped: _ensure_farm_group_type() mirrors the existing cooperative helper (ADR-016 get_or_create_local — signature checked against spp_vocabulary/models/vocabulary_code.py:468), cooperative typing already existed so leaving _create_cooperatives untouched is right, and the tests cover all four surfaces — story farms, the _create_farm helper, the seeded farms, and the container-vs-member split (nice that test_1120_cooperative_container_typed_cooperative walks the memberships and asserts members stay farm).

One blocking item, and it's convention rather than breakage:

1. Version bump

spp_farmer_registry_demo stays at 19.0.2.1.1, and the module is in the 2026.08 release tag. Since this is pure Python in a demo generator (no data files, views, or schema), nothing actually breaks without an upgrade — but the repo rule applies (same-version changes give upgraders no signal), and #441 will eventually enforce it mechanically. One-line fix.

2. Nits (non-blocking, take or leave)

  • _ensure_farm_group_type() is called inside _create_farm for each farm — an uncached get_or_create_local search × 8 story farms. The module already demonstrates both better patterns: hoisted once in _create_cooperatives (cooperative_type_id, line ~1280) and cached in the seeded generator (self._farm_group_type_id). Hoisting or caching would make the three sites consistent.
  • Existing demo databases keep their blank-typed farms — no backfill, which seems fine for demo data as long as QA regenerates rather than expecting the fix to repair old data. Worth a line on the ticket confirming that expectation.
  • The broad except Exception → warning → blank type mirrors the cooperative helper, so consistency wins here — and the new assertions would catch a systemic failure in CI, which makes the silent fallback acceptable.

With the bump added I'm happy to approve.

…er run

Version bump with its changelog entry, per the convention that bumps land in
the PR. Nothing malfunctions without an upgrade — this is Python in a demo
generator — but a same-version change gives upgraders no signal.

The group-type lookup ran once per story farm. It is now resolved once before
the loop and passed down, with the per-farm lookup kept as the fallback for
direct calls such as the tests.

Caching it on the recordset the way the seeded generator does is not available
here: that one is a plain utility class, while this is a TransientModel, and
recordsets use __slots__ — the first attempt at this raised AttributeError
across nine tests.
emjay0921 added a commit that referenced this pull request Aug 19, 2026
Version bump with its changelog entry, per the convention that bumps land in
the PR. The module now has three PRs in flight, so the concrete number is a
merge-time reconciliation: #412 carries .2, this takes .4 and #322 takes .3.

USE_CASES.md is the document this blueprint exists to serve, and it had no EC1
row while its totals still read 21 blueprints and ~730 farms — both undercounts
as soon as this lands. The row is added and the totals now read 22 and ~731.
@emjay0921

Copy link
Copy Markdown
Contributor Author

Thanks — both done. Pushed as 0e85af81.

1. Version bump — 19.0.2.1.3 with its HISTORY line. Note this module now has three PRs in flight: #412 carries .2, this takes .3 and #323 takes .4, to be reconciled in whatever order you merge them.

2. The per-farm lookup — hoisted, and the attempt at your other suggestion is worth recording. I first cached it on the recordset the way seeded_farm_generator does, which failed across nine tests with AttributeError: no __dict__ for setting new attributes: that generator is a plain utility class, while this one is a TransientModel, and recordsets use __slots__. So the lookup is now resolved once before the story loop and passed into _create_farm, with the per-farm lookup kept as the fallback for direct calls such as the tests. Three sites, two patterns, and the difference between them is now the reason rather than an accident.

3. Existing demo databases — confirmed, no backfill: farms already created keep their blank type, and the expectation is that QA regenerates rather than upgrading in place. I have put that on OP#1120 so it is on the ticket rather than only here.

spp_farmer_registry_demo suite: 133 tests, 0 failed. pre-commit clean.

#412 landed the same module's 19.0.2.1.2, so the manifest version and the top of
the changelog both conflicted. Resolved by keeping this branch's 19.0.2.1.3 and
both changelog entries, newest first; README.rst and the description page are
generated from readme/, so they were rebuilt rather than merged by hand.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants