Skip to content

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

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

vistart merged 2 commits into
release/v1.0.0.dev17from
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 shared test suite is where nearly every model in the ecosystem is defined, so its fixtures declared __table_name__, __primary_key__, __pk_auto_generated__ and the locator dunders throughout — declarations the released core no longer reads.

Every one of them was rewritten to the accessor form in a single mechanical change:

  • 534 declarations across 55 files — __table_name__ → table_name(), __primary_key__ → primary_key(), __pk_auto_generated__ → pk_auto_generated(), read_only() where ReadOnlyMixin used to be opted out of with a dunder.
  • model source embedded in strings was migrated too (the CLI fixtures generate model modules from a source string, so the AST sweep cannot see them).
  • contract assertions that read the removed attribute now call the accessor: order_item_class.__pk_auto_generated__ is False became pk_auto_generated() is False, in both the sync and async composite-key suites.

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. No new lint findings: the total drops 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: this repository is a test-suite library, installed into the backends' virtual environments. Its published API is the fixtures and the provider contracts, and those keep their names; only the declaration spelling inside them changed.

Impact on Backend Developers (Custom Implementations):

A backend that provides models or fixtures of its own must declare them through the accessors as well — __table_name__ and friends are no longer read, and a model with no table_name() override now fails with NotImplementedError at the first read.

Related Repositories/Packages

  • rhosocial/python-activerecord — PR #140, merged into release/v1.0.0.dev30.
  • The nine backend repositories — each has a feature/declaration-surface PR that installs this branch from test.yml. This PR must merge first: until it does, those workflows cannot point at release/v1.0.0.dev17, because that branch still declares the removed dunders.

Merge order: this PR → the backend PRs (whose test.yml testsuite ref is then updated from the branch to the release branch).

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 the downstream CI.

Test Plan:

This repository has no test workflow of its own (it is a library that gets installed into other repositories). Its verification is the downstream runs: core's full Python matrix (3.8–3.15t, coverage, benchmarks) and the nine backend matrices all executed against this branch and passed — that is 12,000+ tests in core plus each backend's own version × database matrix.

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 this PR is opened.
  • I have verified that my changes do not introduce SQL injection vulnerabilities.
  • I have checked for potential performance regressions.

Additional Notes

The same migration sweep is applied to every repository in the family, so the fixtures here and the models in the backends stay identical in shape. Migration tooling lives in core's scripts/.

Breaking, following rhosocial-activerecord: model fixtures now override
table_name(), primary_key(), pk_auto_generated(), read_only() and the
locator methods instead of assigning __table_name__ and friends, and
the composite-key contract tests assert pk_auto_generated() rather than
the removed attribute.

534 declarations across 55 files, produced by the core repository\x27s
declaration sweep so both sides stay byte-identical in shape.
@vistart vistart added the enhancement New feature or request label Nov 12, 2026
@vistart vistart self-assigned this Nov 12, 2026
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
45.5% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@vistart
vistart merged commit 710062b into release/v1.0.0.dev17 Nov 12, 2026
1 of 2 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