Table Summarizer Bug on PostgreSQL
So I have a table column defined as such:
I had asked yesterday how do to this price * quantity calculation but I was getting this error:
SQLSTATE[42601]: Syntax error: 7 ERROR: zero-length delimited identifier at or near """"
The query that is generated is
Clearly it's the last line ) AS ""
. I dug into the Summarizer.php
file on line 108.
$query = DB::table($query->toBase());
I haven't really looked at the source code for any of the Filament query stuff before it I changed the line to
$query = DB::table($query->toBase(), 'test');
The above code now works. I'm not saying the table alias needs to be 'test' but I just needed a name to try. I'm not really sure what the best practice (naming) for this would be but I might also cross post this as a GitHub issue.
Just wasn't sure if there was something else on the 'user' side (me, the dev) that I need to do to get this working? (since it also seems like a postgres quirk)19 Replies
This is the page working with the modified
Summarizer.php
I have made a sample project demostrating the issue. Here is the flare page for it. I will have the latest code pushed to it in a moment and will link the repo/file showing the issue.
GitHub
filament-summarize-delim-bug/app/Filament/Resources/InvoiceItemReso...
Contribute to chrisreedio/filament-summarize-delim-bug development by creating an account on GitHub.
Sample repo and linked to line causing the issue
This is the line of Filament that I changed and 'fixed' it.
https://github.com/filamentphp/filament/blob/62cf9339776b6ba517a510774bfe89feb3bd14fe/packages/tables/src/Columns/Summarizers/Summarizer.php#L108
GitHub
filament/packages/tables/src/Columns/Summarizers/Summarizer.php at ...
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS. - filamentphp/filament
Interesting, the code is different here:
https://github.com/filamentphp/filament/blob/62cf9339776b6ba517a510774bfe89feb3bd14fe/packages/tables/src/Concerns/CanSummarizeRecords.php#L70
GitHub
filament/packages/tables/src/Concerns/CanSummarizeRecords.php at 62...
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS. - filamentphp/filament
Will try that here and see if it fixes it
Hmm maybe that was just an accidental omission. Looks like that fixes it
Maybe related. https://github.com/filamentphp/filament/issues/9073
GitHub
Bug with custom summarize in groupings · Issue #9073 · filamentphp/...
Package filament/filament Package Version v3.0.74 Laravel Version v10.28.0 Livewire Version v3.0.8 PHP Version PHP 8.2.11 Problem description With custom summarize-functions and grouping the summar...
Maybe? I haven't done those types yet but mine is a 'hard crash'
Flare link above
like PostgreSQL query error
I am totally uneducated on this part of the Filament source code but I wonder if there is any reason the 'same' line in different in the Summarizer vs the CanSummarizeRecords class.
If I copy the line from CanSummarizeRecords to Summarizer, it works great
Could be a bug. I honestly don’t know. I’ve personally never worked with the summerizers except one time where I had a problem with them not working with Orbit and an sqlite db instance.
I’ve never once actually working with a Postgres db. Lol. Sorry.
I use it exclusively for every client and project I work on heh
Haven't used MySQL/MariaDB in maybe 5ish years?
maybe 4
GitHub
Summarize Query Bug on PostgreSQL · Issue #9177 · filamentphp/filam...
Package filament/filament Package Version v3.0.80 Laravel Version v10.28.0 Livewire Version v3.0.10 PHP Version v8.2.11 Problem description When using a custom Summarizer on PostgreSQL, I get the f...
Bug Posted
First issue posted, Tried to include as much detail as possible. Should I go ahead and submit a PR?
Understandably needs to be reviewed but just figured while I'm in the middle of this
If it’s a solution that doesn’t break anything else then yes submit the PR.
Most of us don’t work with Postgres day to day, so if it solves the problem without breaking existing functionality we are definitely open to it.
Happy to help here where I can
Maybe one of the guys that works on this part of the core will say oh yea, it should have been that way the whole time.
¯\_(ツ)_/¯
I haven't really done
$query = DB::table($query->toBase(), $query->getModel()->getTable());
before but can easily see in the resulting query that leaving out the second argument, generates an invalid query on PostgresOk, PR submitted
https://github.com/filamentphp/filament/pull/9178
GitHub
Fixes Summarize Query Bug on PostgreSQL #9177 by chrisreedio · Pull...
This fixes the bug I documented in #9177 .
Summary
When using a custom Summarizer on PostgreSQL, I get the following QueryException:
SQLSTATE[42601]: Syntax error: 7 ERROR: zero-length delimited id...
I almost feel bad submitting a PR / bug
on one hand, it fixes things, on the other, its more work for you guys lol
Don’t feel bad. We appreciate it.
We are busy but we do care about making a better product when it makes sense. Thank you.