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 Syntax Error in CAST Statement for Postgres Attachment Count Query #202

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

thienvu18
Copy link

When querying the Postgres database, the attachment count query was generated as follows:

select count(*) from "system_files" where "system_files"."attachment_id" = "CAST(some_table"."id" as "TEXT)" and "system_files"."attachment_type" = Some\Model and "field" = images) as "images_count"

This query results in a syntax error due to an incorrect placement of double quotes in the CAST statement.

Changes Made:
Fixed the syntax error by properly wrapping keys before casting.
Used raw queries to prevent issues with double wrapping of keys.

@LukeTowers
Copy link
Member

Thanks for the contribution @thienvu18! Any chance you're able to add a test case for this? Also, is this an issue that's present in Laravel as well?

@thienvu18
Copy link
Author

Thank for your quick reply.

Sorry that I am not good at writing test cases. However, we can produce this bug using our Test Plugin as follows:

  • Precondition: Using Postgres database
  • Step 1: Add a Portfolio count column to user in file plugins/winter/test/models/user/columns.yaml
    portfolio_count:
        label: Portfolio count
        relation: portfolio
        useRelationCount: true
  • Step 2: Access Users list at endpoint backend/winter/test/users. Open list setup then tick Portfolio count then Apply

Then you will get an exception like this
image

Notice at the generated sql statement, you will see an incorrect placement of quotes in the CAST statement

This bug only happens when using postgres database because Dongle will not cast if driver is not pgsql

@LukeTowers LukeTowers added this to the 1.2.8 milestone Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants