[2.x] Remove dead reads of removed validation_rules attribute in Filament field types - #2597
Open
wakqasahmed wants to merge 1 commit into
Open
[2.x] Remove dead reads of removed validation_rules attribute in Filament field types#2597wakqasahmed wants to merge 1 commit into
wakqasahmed wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2568
What
Removes the 10
->when(filled($attribute->validation_rules), ...)guards frompackages/filament/src/FieldTypes/*that read avalidation_rulesattribute onLunar\Core\Models\Attribute.Why
The v2
lunar_attributesschema has novalidation_rulescolumn — field configuration lives in theconfigurationJSON column — and the model defines no cast/accessor for it. Nothing in v2 ever writesvalidation_rules, sofilled($attribute->validation_rules)is alwaysfalseoutside strict model access. UnderModel::preventAccessingMissingAttributes()/Model::shouldBeStrict(), reading it throws: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,configurationkey) that ever populatesvalidation_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
tests/admin/Unit/Support/Forms/AttributeConverters/StrictModeConverterTest.php, which enablesModel::preventAccessingMissingAttributes(), refetches a persistedAttribute(sowasRecentlyCreatedno longer suppresses the exception, matching what happens when Filament loads a record to edit), and callsgetFilamentComponent()for each affected field type. Confirmed this test fails with the exactMissingAttributeExceptionfrom the issue on the unmodified code, and passes after the fix.admintest suite (244 tests, 787 assertions) — all passing.filamenttest suite (45 tests, 100 assertions) — all passing.composer:2-based image withbcmath,exif,intl,gdextensions installed), since PHP is not available on my host directly.I did not run
phpstanor the full monorepo suite (packages/core,packages/panel, etc.) — onlyadminandfilament, the two suites that exercise this code path.