-
Notifications
You must be signed in to change notification settings - Fork 34
ActionEvent
unable to capture changes from non-scalar attribute values
#3980
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
Comments
I have created a minimal repo that demonstrates this issue. It's obviously private, but I've added the package author and @crynobone. |
ActionEvent
unable to capture changes from non-scalar attribute values
There is another but possibly related problem with this same class that appears in Nova. A not-null point field in MySQL must have a spatial index, but this also means that it must have a default value in the model. Given that the property is not scalar, a default value can't be set in the property itself. Setting it in a constructor can't work because prior to casting, the property does not exist, and populating a default overwrites the real value since it seems that Nova (or possibly Laravel itself) only populates the values later. Nova seems to create a model instance even when there are no instances in the DB, and the net result is that the index view in Nova for this same resource reports a |
@Synchro I run into the same issue with Nova 4 and https://github.com/MatanYadaev/laravel-eloquent-spatial Did you found a workaround? |
No, I'm still stuck. The maintainer of that package thinks it's a Nova issue as it generally works outside Nova. From what I've seen, I suspect that's probably correct. |
Ok, thanks. I moved back to grimzy/laravel-mysql-spatial and used the PR from Shift: grimzy/laravel-mysql-spatial#184 |
Same problem. My workaround: class GeoobjectGeometry extends AbstractEloquentModel {
// Casts
protected $casts = [
'center' => Point::class,
'coordinates' => Geometry::class,
];
// .....
public function getRawOriginal($key = null, $default = null)
{
foreach (['center', 'coordinates'] as $cast) {
$this->original[$cast] = Geometry::fromWkb(Arr::get($this->original, $cast, $default));
}
return Arr::get($this->original, $key, $default);
}
} |
@pavloniym While I can see why that would work, it strikes me as a bit hacky, fixing the symptom rather than the cause (which I still don't understand). Is it not likely to cause issues if something that's expecting to have to decode raw values obtained from I can see problems if that function was called twice, since the changes are written back to public function getRawOriginal($key = null, $default = null)
{
if (in_array($key, ['center', 'coordinates'])) {
return Geometry::fromWkb(Arr::get($this->original, $key, $default));
}
return Arr::get($this->original, $key, $default);
} Rather than having to put those property names into an array like that it would be nice to get that info from the |
@Synchro Good point about I have many other "casted" fields in this model (they are skipped from my code example above). And just for simplicity, I listed only specific (Geometry) fields in array. |
In Nova 4, we no longer store changes from non-scalar attributes. |
Description:
I have a resource that contains a field which is a cast object in its own right (actually a Point type, which contains two float properties for lat & long) that are mapped into two
Number
fields in Nova. When updating, the object is converted to a binary string format by its cast so that it's ready to write to the DB, but this string is exposed in Nova and can't be encoded as JSON (because it's not valid UTF-8), so the update fails with this error:I don't know why it's exposed here, but it is.
Two Nova resource fields point at this single underlying object's properties, with
fillUsing
andresolveUsing
to set and get them:ActionEvent::forResourceUpdate
makes the resource, but I note that theoriginal
property mentioned in the error is created like this:getRawOriginal
bypasses casts and exposes the raw binary string, so I'm assuming this is where the problem lies.Ultimately, it's not clear to me whether this is a Nova issue (that it shouldn't be exposing the uncast value) or a problem in the Point class (that it's not casting in the right place).
I apologise that this is not a clearer bug report because I don't know how it's meant to work, so I can't tell what's deviating from what's expected.
Detailed steps to reproduce the issue on a fresh Nova installation:
The text was updated successfully, but these errors were encountered: