Skip to content

Conversation

@anth-volk
Copy link
Contributor

Summary

This PR adds optional tax_benefit_model_version_id filtering to the metadata endpoints (/parameters/, /variables/, /parameter-values/). When only a model name is provided (without an explicit version ID), endpoints now default to returning data from the latest version (determined by created_at timestamp).

Key Changes

  • New shared service: src/policyengine_api/services/tax_benefit_models.py with helper functions:

    • get_latest_model_version() - Get the latest version for a model name
    • get_model_version_by_id() - Get a specific version by UUID
    • resolve_model_version_id() - Resolve version ID from either explicit ID or model name
  • Updated endpoints:

    • /parameters/ - Added tax_benefit_model_version_id filter
    • /variables/ - Added tax_benefit_model_version_id filter
    • /parameter-values/ - Added both tax_benefit_model_name and tax_benefit_model_version_id filters
  • Refactored: /analysis/economic-impact now uses the shared helper instead of its own duplicate function

Behavior

Scenario Result
Only tax_benefit_model_name provided Returns data from latest version
Only tax_benefit_model_version_id provided Returns data from that specific version
Both provided tax_benefit_model_version_id takes precedence
Neither provided Returns all data (no filtering)

Test plan

  • Added 13 new tests for version filtering behavior
  • All 44 unit tests pass
  • Tests cover: latest version default, explicit version filtering, precedence, 404 errors

🤖 Generated with Claude Code

anth-volk and others added 2 commits January 12, 2026 22:11
Add optional `tax_benefit_model_version_id` filter to /parameters/,
/variables/, and /parameter-values/ endpoints. When only model name is
provided (without version ID), endpoints now default to returning data
from the latest version (by created_at timestamp).

Changes:
- Add shared tax_benefit_models service with helper functions
- Update /parameters/ endpoint with version filtering
- Update /variables/ endpoint with version filtering
- Update /parameter-values/ endpoint with model name and version filtering
- Refactor /analysis/economic-impact to use shared helper
- Add comprehensive tests for version filtering behavior

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Tests for aggregate and change-aggregate endpoints were failing because
they passed random UUIDs for simulation IDs, but the endpoints now
validate that simulations exist before creating aggregates.

Changes:
- Add create_dataset and create_simulation factory functions to fixtures
- Add simulation_fixture for tests needing a complete simulation setup
- Update test_outputs.py to create real simulations and mock Modal calls
- Update test_change_aggregates.py similarly with two_simulations fixture
- Add tests for 404 cases when simulations don't exist

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@anth-volk anth-volk marked this pull request as ready for review January 12, 2026 21:43
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