Skip to content

feat!: declare models by overriding accessors, not by dunder - #19

Merged
vistart merged 3 commits into
release/v1.0.0.dev3from
feature/declaration-surface
Nov 12, 2026
Merged

vistart merged 3 commits into
release/v1.0.0.dev3from
feature/declaration-surface

Conversation

@vistart

@vistart vistart commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Description

Follows rhosocial/python-activerecord#140, which makes a model declare its
table name, key, locators and read-only-ness by overriding an accessor
classmethod instead of assigning a class-body dunder. This repository's own
models -- fixtures, providers, examples and embedded model source -- still
declared __table_name__ and friends, which the released core no longer
reads, so every model here was rewritten by the same migration sweep.

What changed in this repository: 19 declaration(s) rewritten to the
accessor form, plus the two forms the class-body sweep cannot see:

  • consumers that read a removed dunder (e.g. Indexed.__table_name__) now call
    the accessor (Indexed.table_name());
  • runtime assignments that declared a name dynamically
    (Author.__table_name__ = "archive") now install the classmethod an override
    would declare (Author.table_name = classmethod(lambda cls: "archive")).

No new lint findings: the totals drop where the removed assignments took their
imports with them.

Type of change

  • feat: A new feature
  • test: Adding missing tests or correcting existing tests (for the new feature)
  • ci: Changes to our CI configuration files and scripts (if related to the new feature)
  • docs: Documentation only changes (if related to the new feature)
  • perf: A code change that improves performance (if part of the feature)
  • chore: Changes to the build process or auxiliary tools and libraries suchs as documentation generation (if related to the new feature)
  • build: Changes that affect the build system or external dependencies (if related to the new feature)
  • revert: Reverts a previous commit

Breaking Change

  • Yes, for end-users (backward-incompatible API changes)
  • Yes, for backend developers (internal architectural changes that may affect custom implementations)
  • No breaking changes

Impact on End-Users:

N/A for this repository's published API: the change is in its fixtures,
providers and examples, which follow core's declaration surface.

Impact on Backend Developers (Custom Implementations):

A backend that ships models declaring the removed dunders must switch to the
accessors, and a backend handler must extend
DDLAnnotationHandler.annotation_types rather than replace it --
UsePartitionKey is part of the core tuple now.

Related Repositories/Packages

  • rhosocial/python-activerecord -- PR #140, merged into
    release/v1.0.0.dev30; this repository's test.yml installs core from that
    branch.
  • rhosocial/python-activerecord-testsuite -- the fixture migration, on
    feature/declaration-surface. Its PR must merge before this one: the
    testsuite ref in test.yml still names that branch, because
    release/v1.0.0.dev17 does not yet contain the migration.
  • The other backend repositories, each on its own feature/declaration-surface.

Testing

  • I have added new tests to cover my changes.
  • I have updated existing tests to reflect my changes.
  • All existing tests pass.
  • This change has been tested on the full version matrix of this backend's CI.

Test Plan:

The full workflow was run on this branch before the ref update: every
Python version × database version job passed. After the ref update the same
matrix runs again, installing the released core.

Checklist

  • My code follows the project's code style guidelines.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation (Docstrings, README.md, etc.).
  • My changes generate no new warnings.
  • I have added a Changelog fragment (changelog.d/<issue_number>.<type>.md).
    • Not applicable yet: a fragment is named by this PR's number, so it is added
      after the PR is opened.
  • I have verified that my changes do not introduce SQL injection vulnerabilities.
  • I have checked for potential performance regressions.

Additional Notes

Migration tooling lives in core's scripts/ (d5_migrate_declarations.py,
p3_fix_reads_and_writes.py): the sweep is AST-located rather than
regex-matched, preserves line endings and spacing, and handles the
type(...) namespace-dict form separately from class bodies.

Breaking, following rhosocial-activerecord: model fixtures and examples
now override table_name(), primary_key(), pk_auto_generated(),
read_only() and the locator methods instead of assigning __table_name__
and friends. The framework stopped reading those dunders, so a model
still declaring them would fail with NotImplementedError at the first
read.

Produced by the core repository's declaration sweep (scripts/
d5_migrate_declarations.py), so every repository in the family carries
the same shape. No new lint findings: the totals drop where the removed
assignments took their imports with them.

CI for this branch installs the family from the matching feature/declaration-surface ref, so a run exercises one revision across core, testsuite and the backend under test rather than a mixture of two.

Includes the two forms the class-body sweep could not see: consumers that read the removed dunders now call the accessor, and runtime assignments that used to declare a table name or schema dynamically now install the classmethod an override would declare.
Workflow 'test.yml' installs this backend's dependencies from the other
repositories in the family. Core's PR #140 is merged into
release/v1.0.0.dev30, so the core ref now names that branch: a run of this
repository tests the released core rather than a feature branch that no
longer exists.

The testsuite ref is unchanged and still names
feature/declaration-surface: its migration has no merge yet, and pointing
it at release/v1.0.0.dev17 would install fixtures that still declare the
removed dunders.
@vistart vistart added the enhancement New feature or request label Nov 12, 2026
@vistart vistart self-assigned this Nov 12, 2026
@codecov

codecov Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.47%. Comparing base (f38f399) to head (c1ef667).

Additional details and impacted files
@@                 Coverage Diff                  @@
##           release/v1.0.0.dev3      #19   +/-   ##
====================================================
  Coverage                77.47%   77.47%           
====================================================
  Files                      140      140           
  Lines                     9826     9826           
  Branches                  1401     1401           
====================================================
  Hits                      7613     7613           
  Misses                    1786     1786           
  Partials                   427      427           
Flag Coverage Δ
mariadb-11.8 77.47% <ø> (ø)
python-3.14 77.47% <ø> (ø)
unittests 77.47% <ø> (ø)

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

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

The testsuite's PR #32 is merged into release/v1.0.0.dev17, so the
testsuite ref now names that branch. Every cross-repository install in a
run therefore resolves to a released artifact: core from
release/v1.0.0.dev30, the testsuite from release/v1.0.0.dev17, and this
repository from its own feature branch.
@sonarqubecloud

Copy link
Copy Markdown

@vistart
vistart merged commit 3434036 into release/v1.0.0.dev3 Nov 12, 2026
20 checks passed
@vistart
vistart deleted the feature/declaration-surface branch November 12, 2026 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant