backdrop-contrib / reference

Defines a field to allow Backdrop entities to reference each other.
GNU General Public License v2.0
4 stars 6 forks source link

PHP fatal when saving a node w/ empty, multi-value reference field #48

Closed jenlampton closed 3 years ago

jenlampton commented 5 years ago

I have added an autocomplete reference field to a content type. It has an unlimited number of values, so that on the node/add form there are several (empty) fields displayed.

When I save this node without adding values into the reference field, I get a fatal error:

EntityStorageException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'field_ref_interviews_target_id' at row 1 in NodeStorageController->save() (line 487 of backdrop/core/modules/node/node.entity.inc).

I think we need some additional validation on the field so that it doesn't attempt to save an empty string.

jenlampton commented 5 years ago

Hm... Well, I fixed the validation, but I'm still getting some errors. I seem to have the same problem with a multi-value integer field, though, so this may be a core issue... see https://github.com/backdrop/backdrop-issues/issues/3873 for more on that. Posting a PR here for more robust validation shortly.

olafgrabienski commented 5 years ago

Hm, the field widgets in the screenshot look more like a link field than a reference field.

jenlampton commented 5 years ago

@olafgrabienski thanks, yeah that was the wrong screenshot :) -- removed

jenlampton commented 3 years ago

Fixed in https://github.com/backdrop-contrib/reference/pull/49

jenlampton commented 3 years ago

Well, #49 doesn't seem to solve all the problems. I'm still seeing:


EntityStorageException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'field_ref_interviews_target_id' at row 1 in NodeStorageController->save() (line 510 of backdrop/core/modules/node/node.entity.inc). 
`1`
jenlampton commented 3 years ago

Well, it's a bit of a hack, but I implemented hook_field_insert() to remove any $items that had empty values, and now my nodes save without fatal errors.