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

Fix model.setAttribute event value #170

Closed
wants to merge 1 commit into from

Conversation

mjauvin
Copy link
Member

@mjauvin mjauvin commented Feb 29, 2024

@mjauvin
Copy link
Member Author

mjauvin commented Feb 29, 2024

@bennothommo any idea about the larastan error ?

@mjauvin mjauvin changed the title Fix model.setAttribute event value Fix model.setAttribute event value Feb 29, 2024
@bennothommo
Copy link
Member

@mjauvin I have no idea - it seems to be happening randomly at the moment. Retrying the test usually resolves it.

@LukeTowers
Copy link
Member

It could just be because it's late and I should probably go to bed, but why exactly is this necessary? This feels very wrong, to be modifying the value returned from the event; why wouldn't it be the job of the listener to retrieve the accessor value if it didn't like the value as provided by this event?

@bennothommo
Copy link
Member

bennothommo commented Mar 1, 2024

It goes to the expectation of the event - given that there's a beforeSetAttribute event as well, and the value itself is potentially modified from when it first went it to the setAttribute() method (it could be trimmed or JSON-encoded or modified by the beforeSetAttribute event), the implication is that the setAttribute event (being an after the fact event) should contain what the attribute is now it has been set, so arguably, this should be after it has been mutated as well.

@LukeTowers
Copy link
Member

But the setAttribute is dealing with the raw value of the attribute as stored in the attributes array, it's not dealing with the value as potentially mutated through an accessor method; so I'm concerned that this will break things.

Why does it need to be done this way, can't the consumer of this event change what it's doing if it's having problems with that value?

@bennothommo
Copy link
Member

My main concern is that there's potentially a disconnect between the value that's provided to the event and the value that's actually stored in the attributes array, and I was simply following the behaviour that's being exhibited by these lines:

In that they're modifying the original value set in the parameters (as $value) before being sent to the setAttribute event.

If the intention of the event was to send the value pre-modification to the setAttribute event, then it's not doing that currently and should probably be fixed. If on the other hand, it was to actually be what's stored in the attributes array at that point, then it needs to be modified to include any modification by a mutator, hence changing the event as @mjauvin has proposed.

I'm certainly amenable to adding this as an additional parameter to the event if we must, but I'd rather fix the oversight if possible.

@mjauvin mjauvin added this to the 1.2.5 milestone Mar 5, 2024
@LukeTowers LukeTowers modified the milestones: 1.2.5, 1.2.6 Mar 11, 2024
@mjauvin mjauvin closed this Apr 13, 2024
@mjauvin mjauvin deleted the fix-model-setattribute-event branch December 4, 2024 17:09
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.

Model mutators not working using SettingsModel behavior
3 participants