Skip to content

Conversation

@mo7ameds7awky
Copy link

@mo7ameds7awky mo7ameds7awky commented Aug 12, 2024

Issue Summary:
We identified an issue with the whereNotMorphedTo method in the Laravel framework. The issue stems from the use of the null safe operator <=>, which is not compatible with SQLite and PostgreSQL databases. This operator, while functioning correctly in MySQL, causes errors when used with other database systems.

The following error message was encountered during execution:

PDOException: SQLSTATE[HY000]: General error: 1 near ">": syntax error in vendor/laravel/framework/src/Illuminate/Database/Connection.php:407

Solution:
To ensure cross-database compatibility and to avoid unexpected errors, we propose removing or replacing the null safe operator <=> in the whereNotMorphedTo method. This change will enhance the framework's reliability across different database systems.

References:
This issue was discussed and partially addressed in a previous PR: #42878, which initially proposed the use of the null safe operator.

@taylorotwell
Copy link
Member

Seems like just removing code could break other use cases?

@taylorotwell
Copy link
Member

This would just reintroduce another bug?

@taylorotwell taylorotwell marked this pull request as draft August 13, 2024 17:19
@mo7ameds7awky
Copy link
Author

I believe there is no bug in the current implementation of the whereNotMorphedTo method.

The whereNotMorphedTo method's first parameter does not receive null models. The previous discussion about null values #42264 (comment) was a hypothetical scenario that does not occur in practice.

@mo7ameds7awky mo7ameds7awky marked this pull request as ready for review September 1, 2024 16:10
@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions!

@chrisreedio
Copy link

@mo7ameds7awky I've run into this issue on Postgres. Since this PR was closed, did you ever come up with a work around?

@mo7ameds7awky
Copy link
Author

@chrisreedio Yes, there are two workarounds here, first you can revert your condition for example:
->whereNot(fn (Builder $query) => $query->whereMorphedTo('relation-name', $model))
, second you can convert this one function into two checks for example:
->where('model_type', 'type')->where('model_id', 'id')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants