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 and/or function argument to compile check bool expression #4345

Merged
merged 4 commits into from
Nov 15, 2024

Conversation

E-anae
Copy link

@E-anae E-anae commented Nov 15, 2024

Currently if you try putting any sort of expression in a and function of diesel it will not be detected at compile time but will raise an error at runtime

@Ten0 Ten0 self-assigned this Nov 15, 2024
@Ten0 Ten0 marked this pull request as ready for review November 15, 2024 15:57
@Ten0
Copy link
Member

Ten0 commented Nov 15, 2024

Thank you for the fix! Tested compilation on our codebase and this does not cause any issue.

@weiznich it looks like we probably want to add this to #4343 :)

@Ten0 Ten0 changed the title Fix and/or function attribute to be a bool expression Fix and/or function argument to compile check bool expression Nov 15, 2024
@weiznich weiznich added this pull request to the merge queue Nov 15, 2024
@weiznich
Copy link
Member

@Ten0 I will add it to the backport PR as soon as I'm to work.

Merged via the queue into diesel-rs:master with commit e659b01 Nov 15, 2024
48 checks passed
@Roardom
Copy link

Roardom commented Nov 16, 2024

Hi, maybe I'm misunderstanding, but it looks like this restriction is placed on all database backends. The query provided in the test works fine for mysql on 2.2.4. Maybe it should only restrict postgres instead?

@weiznich
Copy link
Member

@Roardom Thanks for raising that concern. You are right that this kind of query is allowed with mysql, it seems to be just another syntax for column IS NOT NULL. As there is currently no easy way to place this restriction as backend specific restriction I would like to move forward anyway as that's a rather critical bugfix for the postgresql/sqlite backend. I'm open to other opinions here, but I would like to ask for proposed solutions then.

@Roardom
Copy link

Roardom commented Nov 17, 2024

While not a complete solution, it should at least be highlighted in the release notes as a breaking change for users supporting mysql backends. I saw this change and immediately thought of similar queries in my code. But I double checked, and I only use it inside SUM(), such as SUM(NOT active AND visible) which already isn't permitted in diesel (since boolean doesn't implement foldable requiring raw queries).

it seems to be just another syntax for column IS NOT NULL

I believe column IS NOT NULL AND column != 0 AND column != '' is more accurate (0 and '' would depend on the type). There might be other variations as well.

weiznich added a commit to weiznich/diesel that referenced this pull request Nov 21, 2024
Fix and/or function argument to compile check bool expression
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.

4 participants