Skip to content

Build typed control totals from the generated ReportingControlTotal model #1487

Open

Description

@KonstantinMirin

Problem

_typed_control_totals in the producer builds ReportingControlTotalRecord dataclasses. That class re-declares the schema's name and value patterns and the 32-character unit bound by hand, and serializes with its own to_wire(). The SDK already ships the generated model for the same schema: adcp.types.ReportingControlTotal, with ReportingControlTotal1 (integer) and ReportingControlTotal2 (decimal) carrying the same patterns. The patterns match today. When the schema changes, the generated model picks up the change on the next sync, and the hand-written copy does not.

Evidence

All references are to main at 47084e83a.

  • src/adcp/reporting/ledger/producer.py:243-265: _typed_control_totals constructs ReportingControlTotalRecord(total.name, total.value, total.value_type, total.unit or units.get(total.name)) for each manifest total.

  • src/adcp/reporting/evidence.py:196-232: ReportingControlTotalRecord.__post_init__ re-declares the patterns:

    if re.fullmatch(r"[A-Za-z][A-Za-z0-9_.:-]{0,127}", self.name) is None:
    ...
    pattern = (
        r"-?(?:0|[1-9][0-9]*)"
        if self.value_type == "integer"
        else r"-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?"
    )
    ...
    _public_text(self.unit, maximum=32)
  • src/adcp/types/domains/core/reporting_control_total.py:13-57: ReportingControlTotal1 and ReportingControlTotal2 declare pattern='^[A-Za-z][A-Za-z0-9_.:-]{0,127}$', pattern='^-?(?:0|[1-9][0-9]*)$', pattern='^-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?$', and max_length=32 on unit.

  • src/adcp/types/__init__.py:171: ReportingControlTotal is a public export.

  • No module under src/adcp/reporting/ledger/row_*.py, producer.py, or evidence.py imports adcp.types. Two other ledger modules do (consumer_status.py:460, status_server.py:12), so the dependency direction is established.

Suggested fix

Construct ReportingControlTotal instances in _typed_control_totals and hash their wire form. Keep ReportingControlTotalRecord as a thin adapter (or alias) while the retained evidence column and from_wire depend on it, and delete the duplicated regexes from __post_init__. This is protocol shape, so it is independent of the storage layer.

Introduced in #1459.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpythonPull requests that update python code

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions