Skip to content

feat: Allow to automatically run group rules on primary key#300

Merged
Oliver Borchert (borchero) merged 1 commit intomainfrom
pk-rule
Mar 23, 2026
Merged

feat: Allow to automatically run group rules on primary key#300
Oliver Borchert (borchero) merged 1 commit intomainfrom
pk-rule

Conversation

@borchero
Copy link
Copy Markdown
Member

Motivation

When using dataframely schemas as mixins, it is sometimes convenient to define rules in the mixins. Currently, it is not possible, however, to define group rules that dynamically apply to the primary key of the schema adopting the mixin.

Changes

  • Allow to set group_by="primary_key" in the @dy.rule decorator to dynamically resolve to all primary key columns

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends Dataframely’s @dy.rule group-rule functionality to support group_by="primary_key", allowing mixins (and other reusable schema components) to define group rules that automatically group by the adopting schema’s primary key.

Changes:

  • Extend @dy.rule(group_by=...) to accept the sentinel value "primary_key" and resolve it to Schema.primary_key() at class creation time.
  • Raise an ImplementationError when "primary_key" is requested but the schema has no primary key columns.
  • Add tests covering single/composite primary keys, no-primary-key error behavior, and mixin behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
dataframely/_rule.py Adds "primary_key" sentinel support to group-rule creation and documents the new behavior.
tests/schema/test_rule_implementation.py Adds test coverage for primary-key-based grouping, including mixin usage.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (1527718) to head (c2106c6).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #300   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           54        54           
  Lines         3127      3133    +6     
=========================================
+ Hits          3127      3133    +6     

☔ View full report in Codecov by Sentry.
📢 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.

@borchero Oliver Borchert (borchero) merged commit 2534bf7 into main Mar 23, 2026
36 checks passed
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.

3 participants