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
Backticks inserted into wrong place when executing DB::raw() expressions alongside ->withSum(...) #49894
Comments
From the upgrade guide:
I'm sorry, but we no longer support casting to a string. Did you already try just using the DB::raw() call without the type cast? |
@driesvints The string cast is just to make phpstan as happy as you are at hitting that close as completed button because the The issue here is that the wrapping is being performed incorrectly. |
I don't really appreciate the passive/aggressive tone here. Feel free to attempt a PR to the docs or the framework if you want. |
No worries will do, thanks for the help 👍 |
I can see the issue here, the wrap function in Grammar.php does a check to see if the value is an expression, however the changes implemented in #44784 (removing the __toString() method) have broken the ability for this check to work (at least with the relation aggregate methods) as we can no longer pass an expression through to this. |
@tpetry could you wage in here maybe? |
Its probably a missing expression handling somewhere in |
Thanks @tpetry |
I've verified the issue and started working on a fix. The aggregate functions hadn't been documented to support expressions. |
Thank you both! @tpetry, a quick question if you don't mind (this could be me misunderstanding): This line
Grammar be passed through yet I can see nowhere that it is actually used or required? Without forcibly requiring this then we would be able to re-implement the __toString() method which would fully resolve this issue and I believe would not break your original PR?
As my colleague @morganarnel has pointed out to me this morning, we believe this issue may extend further than just aggregate usages and in fact may impact any |
The
The Laravel core has been changed to handle |
@tpetry thank you! I understand now (I forgot your Expression extensions for a moment there..), greatly appreciate you working on a fix for this! 🙂 |
@morganarnel @john-dent PR #49912 will fix this issue |
Laravel Version
10.42.0
PHP Version
8.2.12
Database Driver & Version
MySQL 8.2.0 on linux/arm64
Description
Recently upgraded to Laravel 10 from 9 - have substituted our
DB::raw()
expressions with the new(string) DB::raw(...)->getValue(DB::connection()->getQueryGrammar())
as directed in the upgrade guide because the->withSum()
no longer accepts an expression (presumably down to the loss of string casting).As you can see from the above screenshot the expression has been grossly misinterpreted and the backticks have been placed in some pretty wacky places. Adding the backticks myself didn't work.
Here's a snippet of one of the offending withSum lines
Steps To Reproduce
Try a funky expression in a withSum
The text was updated successfully, but these errors were encountered: