Skip to content
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

Fix broken assert(is_numeric($sql)) in DateAddFunction and DateSubFunction #11240

Closed
ondrejmirtes opened this issue Feb 9, 2024 · 2 comments · Fixed by #11243
Closed

Fix broken assert(is_numeric($sql)) in DateAddFunction and DateSubFunction #11240

ondrejmirtes opened this issue Feb 9, 2024 · 2 comments · Fixed by #11243
Labels
Milestone

Comments

@ondrejmirtes
Copy link
Contributor

Bug Report

Q A
BC Break yes
Version 3.0

Summary

I'm working on ORM 3 and DBAL 4 support on phpstan-doctrine, and I have this test case:

				SELECT		DATE_ADD(m.datetimeColumn, m.intColumn, \'day\'),
							DATE_ADD(m.stringNullColumn, m.intColumn, \'day\'),
							DATE_ADD(m.datetimeColumn, NULLIF(m.intColumn, 1), \'day\'),
							DATE_ADD(\'2020-01-01\', 7, \'day\')
				FROM		QueryResult\Entities\Many m

Doctrine crashes on this line:

assert(is_numeric($sql));

The $sql value is: m0_.intColumn.

I think the assert assumption is wrong, as interval does not have to refer to a scalar value, but can be a column as well. The job of this part of the codebase is to just generate the correct SQL query to execute against the database.

Same problem is in DateSubFunction too.

Current behavior

assert(): assert(is_numeric($sql)) failed

Expected behavior

It should work and generate the right SQL.

ondrejmirtes added a commit to phpstan/phpstan-doctrine that referenced this issue Feb 9, 2024
ondrejmirtes added a commit to phpstan/phpstan-doctrine that referenced this issue Feb 9, 2024
@derrabus derrabus added the Bug label Feb 9, 2024
ondrejmirtes added a commit to phpstan/phpstan-doctrine that referenced this issue Feb 9, 2024
ondrejmirtes added a commit to phpstan/phpstan-doctrine that referenced this issue Feb 9, 2024
ondrejmirtes added a commit to phpstan/phpstan-doctrine that referenced this issue Feb 9, 2024
ondrejmirtes added a commit to phpstan/phpstan-doctrine that referenced this issue Feb 9, 2024
@derrabus
Copy link
Member

derrabus commented Feb 9, 2024

That looks like a valid bug. PR welcome if someone wants to give it a try before I find the time.

@ondrejmirtes
Copy link
Contributor Author

I'm trying: #11243

@derrabus derrabus changed the title 3.0 - DQL AST - assert(is_numeric($sql)) is wrong in DateAddFunction and DateSubFunction Fix broken assert(is_numeric($sql)) in DateAddFunction and DateSubFunction Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants