Skip to content

Default metadata endpoints to latest model version and add version filtering #98

@anth-volk

Description

@anth-volk

Summary

All metadata endpoints currently return data from all model versions when tax_benefit_model_name is provided. They should default to the latest TaxBenefitModelVersion (by created_at DESC) and accept an optional tax_benefit_model_version_id for pinning to a specific older version.

Additionally, the by-name and children endpoints currently accept country_id instead of tax_benefit_model_name, which is inconsistent with the other endpoints. This should be unified.

Changes required

New service helper

  • src/policyengine_api/services/tax_benefit_models.py with resolve_model_version_id() — resolves an optional model name + optional version ID into the correct TaxBenefitModelVersion UUID

Endpoint changes

Endpoint Change
GET /parameters/ Add optional tax_benefit_model_version_id. Default to latest version when tax_benefit_model_name provided.
POST /parameters/by-name Replace country_id with tax_benefit_model_name. Add optional tax_benefit_model_version_id.
GET /parameters/children Replace country_id with tax_benefit_model_name. Add optional tax_benefit_model_version_id.
GET /variables/ Add optional tax_benefit_model_version_id. Default to latest version.
POST /variables/by-name Replace country_id with tax_benefit_model_name. Add optional tax_benefit_model_version_id.
GET /parameter-values/ Add optional tax_benefit_model_name and tax_benefit_model_version_id. Filter via join through Parameter.

No schema/migration changes needed

The tax_benefit_model_version_id FK already exists on Parameter and Variable models.

Supersedes

This supersedes PR #72 (fix/allow-filtering-by-version-id), which took a similar approach but removed the by-name and children endpoints.

Target branch

app-v2-migration

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions