Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #9949 Unable to update field values for custom field without changing the name #12011

Conversation

inietov
Copy link
Collaborator

@inietov inietov commented Oct 21, 2022

Description

When updating Custom Fields via the API the Validator was using the rules from the CustomField model. Which works well when creating a new CustomField ie: Name is required because we cannot create a CustomField without one, and cannot already be taken on another CustomField. But when we are updating one this rule is causing that we need to pass the name field to the PUT method and if passed we cannot pass the same name that field already has.

I'm creating a custom validator, because the PUT method has the name and element fields as required, but we can pass the same existent values if we don't want to change the name, for example. My problem is the PATCH method, because that can change whatever it passes. So I don't know how to 'detect' when it's a PATCH so I can remove those validation rules...

Fixes #9949

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Test Configuration:

  • PHP version: 8.1
  • MySQL version: 8.0.23
  • Webserver version: nginx/1.19.8
  • OS version: Debian 10

Checklist:

Copy link
Collaborator

@uberbrady uberbrady left a comment

Choose a reason for hiding this comment

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

Good catch! Yes, that looks like a bug - we shouldn't be validating against the field's validation rules, we should be validating against the rules for Custom Fields themselves.

That being said, If we're going to put these validation rules on a Custom Field (and I think we should!) then we should put them into the protected $rules element within the Custom Field model itself, and be prepared for the save() method to fail (when validation doesn't pass). One thing we can also protect against here is if a user tries to have two custom fields with the same name - which we should try to prevent.

If you can do something along those lines (and I'll be happy to help!) I think that will be the best solution to the problem that works the best way with what we are already doing in most other places.

Thanks!

@snipe snipe closed this Nov 17, 2022
snipe added a commit that referenced this pull request Nov 17, 2022
Fixed #9949 - PATCH to custom fields failing on validation (alt approach to #12011)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants