question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] Version 4.1.52 broke inline_create

See original GitHub issue

Bug report

What I did

Defined a field to use inline_create with:

$this->crud->addField([
    'type' => 'relationship',
    'name' => 'customer_id',
    'label' => 'Customer',
    'ajax' => true,
    'inline_create' => true,
]);

What I expected to happen

The field was working normally before updating to Backpack version 4.1.53, showing the button to open the modal and create the related model.

What happened

In the “create operation”, even though there is no value in the field, the file fetch_or_create tries to get a value from the database passing an empty string as the $current_value on line 37.

SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type bigint: "" (SQL: select * from "customers" where "id" = ) (View: vendor/backpack/crud/src/resources/views/crud/fields/relationship/fetch_or_create.blade.php)

What I’ve already tried to fix it

Commenting the ajax and inline_create attributes stops the error.

I believe what caused this was a change from PR #3671 that changed to a strict comparison of $current_value and false.

When the field is empty, the previous line sets the empty string as the value for $current_value.

Before the change, since it was a loose comparison, the code would not try to access the database inside the if block.

PHP VERSION:

PHP 7.4.3 (cli) (built: Aug 13 2021 05:39:12) ( NTS ) Copyright © The PHP Group Zend Engine v3.4.0, Copyright © Zend Technologies with Zend OPcache v7.4.3, Copyright ©, by Zend Technologies

LARAVEL VERSION:

v8.61.0@3d528d3d3c8ecb444b50a266c212a52973a6669b

BACKPACK VERSION:

4.1.53@8698b8ed51e8b18e311f928f6f80a7161f1eb172

DATABASE VERSION:

PostgreSQL 12.7

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
pxpmcommented, Sep 20, 2021

Hello @matheusb-comp

Thanks for the report.

I can confirm that this happens ONLY in PostGres! MySQL would not complain from such query: select * from iconswhereid = '' this would just return empty result from MySQL. But in PG it would throw that error.

I am working on a fix for it, I should get back to you guys in a moment here. Just write it down so @promatik don’t lose time here debugging!

Best, Pedro

1reaction
pxpmcommented, Sep 20, 2021

You are welcome and thanks for getting back with the feedback.

Sorry for introducing the bug, If you were not using PG I am sure I would not notice it in the near future!

Glad we could workout the solution. You are happy, we are happy, future users would be happy! Win-Win-Win!

Best, Pedro

Read more comments on GitHub >

github_iconTop Results From Across the Web

Backpack v4.1.x (Continuous Dev) · GitHub
non breaking change. Changes approved. From ✓ Done. Copy card link. fix usage of repeatable inside inline create modal CRUD#3302 opened by pxpm....
Read more >
backpack/crud - Packagist
patch - bug fixes & small non-breaking changes; historically every week; update takes seconds;. When we release a new Backpack\CRUD version, all paid...
Read more >
Download the PHP package backpack/crud without Composer
On this page you can find all versions of the php package backpack/crud. ... patch - bug fixes & small non-breaking changes; historically...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found