Skip to content

[2.x] Remove dead reads of removed validation_rules attribute in Filament field types - #2597

Open
wakqasahmed wants to merge 1 commit into
lunarphp:2.xfrom
wakqasahmed:fix/attribute-field-validation-rules
Open

[2.x] Remove dead reads of removed validation_rules attribute in Filament field types#2597
wakqasahmed wants to merge 1 commit into
lunarphp:2.xfrom
wakqasahmed:fix/attribute-field-validation-rules

Conversation

@wakqasahmed

Copy link
Copy Markdown

Closes #2568

What

Removes the 10 ->when(filled($attribute->validation_rules), ...) guards from packages/filament/src/FieldTypes/* that read a validation_rules attribute on Lunar\Core\Models\Attribute.

Why

The v2 lunar_attributes schema has no validation_rules column — field configuration lives in the configuration JSON column — and the model defines no cast/accessor for it. Nothing in v2 ever writes validation_rules, so filled($attribute->validation_rules) is always false outside strict model access. Under Model::preventAccessingMissingAttributes() / Model::shouldBeStrict(), reading it throws:

Illuminate\Database\Eloquent\MissingAttributeException
The attribute [validation_rules] either does not exist or was not retrieved for model [Lunar\Core\Models\Attribute].

This breaks opening any attribute-backed edit form (e.g. editing a Product) whenever strict mode is enabled.

This follows option 1 from the issue: the minimal fix, since there is currently no v2 mechanism (getConfigurationFields() entry, configuration key) that ever populates validation_rules — the reads are dead v1 leftovers. Per-attribute validation rules as a genuine v2 feature (option 2 in the issue) would be a separate, larger change requiring a new configuration field and UI, and is out of scope for this fix.

Testing

  • Added tests/admin/Unit/Support/Forms/AttributeConverters/StrictModeConverterTest.php, which enables Model::preventAccessingMissingAttributes(), refetches a persisted Attribute (so wasRecentlyCreated no longer suppresses the exception, matching what happens when Filament loads a record to edit), and calls getFilamentComponent() for each affected field type. Confirmed this test fails with the exact MissingAttributeException from the issue on the unmodified code, and passes after the fix.
  • Ran the full admin test suite (244 tests, 787 assertions) — all passing.
  • Ran the full filament test suite (45 tests, 100 assertions) — all passing.
  • All command run via Docker (composer:2-based image with bcmath, exif, intl, gd extensions installed), since PHP is not available on my host directly.

I did not run phpstan or the full monorepo suite (packages/core, packages/panel, etc.) — only admin and filament, the two suites that exercise this code path.

Filament field types called $attribute->validation_rules, an attribute
that v2 dropped in favour of the configuration JSON column. Under strict
model access this throws MissingAttributeException when opening an
attribute-backed edit form; without strict mode the guard was always
false since nothing writes validation_rules. Remove the 10 dead reads.

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

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant