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 null value errors in attribute casting #1772

Conversation

ryanmitchell
Copy link
Contributor

When you add a new attribute and edit a item but dont set a value for it, you receive an error due to the value being null when the cast tries to work out its type.

This PR works around that issue by ignoring null values.

Copy link

vercel bot commented May 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lunar-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 23, 2024 10:06am

@alecritson
Copy link
Collaborator

@ryanmitchell Are you able to either create an issue with steps or provide steps on how to reproduce this the issue this is fixing as currently I'm not getting any errors

@ryanmitchell
Copy link
Contributor Author

So it happens for me when I create a new product variant attribute then edit an existing variant but dont blur that field (so leave it blank and never touch it).

@alecritson
Copy link
Collaborator

I just tried these steps and everything seemed ok 🤔 here's a quick video of what I did.

https://www.loom.com/share/25293d74d5ef47ce9b0fe5080e816114

@ryanmitchell
Copy link
Contributor Author

Here's my error trace: https://flareapp.io/share/17WvaBnP
Clean install - with a lot of attribute fields and groups.

@alecritson
Copy link
Collaborator

Here's my error trace: https://flareapp.io/share/17WvaBnP Clean install - with a lot of attribute fields and groups.

What does your attribute data look like for the offending product variant?

@ryanmitchell
Copy link
Contributor Author

{"publication-status": {"value": "In Print", "field_type": "Lunar\\FieldTypes\\Dropdown"}, "onix-country-of-manufacture": {"value": "asdsdasdas", "field_type": "Lunar\\FieldTypes\\Text"}}```

Tried nulling it but no difference there.

@alecritson
Copy link
Collaborator

{"publication-status": {"value": "In Print", "field_type": "Lunar\\FieldTypes\\Dropdown"}, "onix-country-of-manufacture": {"value": "asdsdasdas", "field_type": "Lunar\\FieldTypes\\Text"}}```

Tried nulling it but no difference there.

Strange mine looks basically the same yet unable to reproduce this one, things seem to work as expected.

@ryanmitchell
Copy link
Contributor Author

Not sure why. I'm on a clean install and it happens consistently on every product.

@glennjacobs glennjacobs changed the title [1.x] Fix null value errors in attribute casting Fix null value errors in attribute casting May 22, 2024
@alecritson
Copy link
Collaborator

Not sure why. I'm on a clean install and it happens consistently on every product.

I just tried on a new install of the starter kit and I still wasn't able to reproduce this. Are you able to dd the $value to see what's being sent up whilst it's being saved? Bit of a head scratcher for sure.

@glennjacobs Might need to ask if you can reproduce this

@ryanmitchell
Copy link
Contributor Author

Sure, so its:

CleanShot 2024-05-23 at 08 07 59@2x

@alecritson
Copy link
Collaborator

Sure, so its:

CleanShot 2024-05-23 at 08 07 59@2x

Very strange, how are your attributes set up? Specifically the ones which are showing as null?

@ryanmitchell
Copy link
Contributor Author

Nothing abnormal - its a pretty vanilla build (just starting it):

CleanShot 2024-05-23 at 08 29 49@2x

@alecritson
Copy link
Collaborator

Nothing abnormal - its a pretty vanilla build (just starting it):

CleanShot 2024-05-23 at 08 29 49@2x

Very strange, so if I save a variant which has a new attribute and dd on the handleRecordUpdate in BaseEditRecord then my attribute data looks like this

image

if I so the same on a product, it looks like this:

image

Everything seems to have an appropriate field type set with a value 🤔 you haven't got any custom code that uses hooks or anything? Seems like the issue is the panel isn't hydrating the form attribute data for some reason

@ryanmitchell
Copy link
Contributor Author

Nope it's a pretty clean install at this point. Oh well, must be something on our side, but I've no idea what.

That said, it's a pretty simple PR - if the value is null you wouldn't want it being saved anyway?

@alecritson
Copy link
Collaborator

Weirdly this just came up on one of our sites 😅 I've assigned @glennjacobs to see if he is able to reproduce. My only concern would be that the attributes should have the correct mapping on save and I'd be worried this would just be masking another issue altogether.

@ryanmitchell
Copy link
Contributor Author

Oh good that you can see it now, and that I'm not losing my mind.

@lguichard
Copy link
Contributor

I have the bug in the Brand edit page but i can't reproduce the steps

@wychoong
Copy link
Contributor

I’m having same issue and replicable with these steps #1772 (comment)

My issue is with Toggle field and so far I traced to this line

return $this->getValue() ?? '';

By making sure it’s returning 0 or 1 only

It also makes me think is there a change in livewire that the issue only happens now 😂

@wychoong wychoong mentioned this pull request May 24, 2024
@alecritson
Copy link
Collaborator

@ryanmitchell Finally managed to consistently reproduce this, for me it was to add a new attribute to a different product type and then try switching that product to that type, which caused the error.

I switched to the branch on @wychoong 's PR and the error went away

@ryanmitchell
Copy link
Contributor Author

Great!

@ryanmitchell ryanmitchell deleted the fix/null-values-in-attribute-cast branch May 24, 2024 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants