Skip to content

Allow a compound to declare an ordered validation - #7580

Open
laritakr wants to merge 2 commits into
mainfrom
compound-ordered-validation
Open

Allow a compound to declare an ordered validation#7580
laritakr wants to merge 2 commits into
mainfrom
compound-ordered-validation

Conversation

@laritakr

@laritakr laritakr commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

A compound metadata property can declare a rule relating two of its sub-properties, so an entry whose end date falls before its start date is refused.

Details

Nothing previously stopped a reversed range from saving: validation was per-sub-property, with no way to express a rule across two. This validation is declared on the compound rather than a sub-property:

  dates:
    data_type: array
    type: hash
    validations:
      - { type: ordered, before: start_date, after: end_date }
  • ordered compares dates. A blank after (the usual case for an optional end date) is allowed, as are equal values; a value that does not parse as a date is skipped rather than flagged.
  • One message per broken rule, not per offending row, matching how missing_required_subproperties dedupes. A row still missing a required: sub-property reports only that, so a half-filled entry doesn't raise two complaints.
  • An unrecognized type: is carried through rather than rejected, so a profile written against a newer Hyrax still loads. A new profile-validation warning surfaces it, which stops a misspelling (ordred) from silently disabling the rule.
  • Opt-in: compounds without validations: behave exactly as before.

A compound can now declare a rule relating two of its sub-properties, so
an entry whose end date falls before its start date is refused:

    dates:
      validations:
        - { type: ordered, before: start_date, after: end_date }

`required:` constrains one sub-property at a time, leaving no way to
express a relationship between two. An unrecognized rule type is carried
through rather than rejected, so a profile written against a newer Hyrax
still loads; profile validation warns about it, which keeps a misspelled
rule from silently doing nothing.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@laritakr laritakr added the notes-minor Release Notes: Non-breaking features label Aug 11, 2026
@laritakr
laritakr requested a lite review from Copilot August 11, 2026 20:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds support for compound-level validation rules so a compound property can enforce ordering constraints across two sub-properties (e.g., end date must not precede start date), with profile-time warnings for rules that would otherwise be silently ignored.

Changes:

  • Introduces normalized validations: on compound definitions and implements an ordered rule in Hyrax::CompoundEntryValidation.
  • Adds a flexible-schema validator that warns on unknown/incomplete compound validation rules (non-blocking).
  • Adds specs, documentation, and I18n strings for the new ordering rule and warnings.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
spec/services/hyrax/flexible_schema_validators/compound_validations_validator_spec.rb Tests warning behavior for unknown/incomplete compound validation rules.
spec/services/hyrax/compound_schema_spec.rb Verifies compound validations: are carried through schema definitions and default to empty.
spec/services/hyrax/compound_entry_validation_spec.rb Tests ordered-rule behavior (in-order, equal, blank end date, deduped violations).
documentation/compound_fields.md Documents validations: and the ordered rule semantics and messaging.
config/locales/hyrax.en.yml Adds end-user error message for out-of-order entries and validator warning messages.
app/services/hyrax/flexible_schema_validators/compound_validations_validator.rb Implements warning-only profile validation for compound validations: rules.
app/services/hyrax/flexible_schema_validator_service.rb Wires the new compound validations validator into overall schema validation.
app/services/hyrax/compound_schema.rb Normalizes compound validations: rules into the compound definition.
app/services/hyrax/compound_entry_validation.rb Implements ordered validation and emits :out_of_order violations.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +111 to +118
def comparable(row, key)
value = row[key] || row[key.to_sym]
return if value.blank?

Date.parse(value.to_s)
rescue ArgumentError, TypeError
nil
end
@github-actions

Copy link
Copy Markdown

Test Results

1 928 tests  +2   1 928 ✅ +2   0s ⏱️ ±0s
    1 suites ±0       0 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit bcef2c1. ± Comparison against base commit 4343ff2.

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

Labels

notes-minor Release Notes: Non-breaking features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants