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

Postgres column name with "-" not correctly handled #82

Open
afdev82 opened this issue Apr 12, 2022 · 0 comments
Open

Postgres column name with "-" not correctly handled #82

afdev82 opened this issue Apr 12, 2022 · 0 comments

Comments

@afdev82
Copy link

afdev82 commented Apr 12, 2022

Environment

  • Ruby 3.0.3p157
  • Rails 6.1.5
  • WiceGrid 4.1.0 3ae1bec

Description of issue

I found that if the column name contains a "-" in it, I get an error when I filter the table.
In fact I saw from the stack trace and the SQL log what's happening:

SELECT DISTINCT "configurations"."configuration_id" AS alias_0, "configurations"."configurations"."configuration_id" FROM "configurations"."configurations" LEFT OUTER JOIN "alchemy_sites" ON "alchemy_sites"."id" = "configurations"."configurations"."website_id" LEFT OUTER JOIN "system"."countries" ON "system"."countries"."country_id" = "configurations"."configurations"."country_id" LEFT OUTER JOIN "configurations"."custom_models" ON "configurations"."custom_models"."custom_model_id" = "configurations"."configurations"."custom_model_id" LEFT OUTER JOIN "system"."users" ON "system"."users"."user_id" = "configurations"."configurations"."user_id" LEFT OUTER JOIN "configurations"."prices" ON "configurations"."prices"."configuration_id" = "configurations"."configurations"."configuration_id" WHERE (("configurations"."configurations"."is_preset" = TRUE AND "configurations"."configurations"."measurement_system" = 'metric' AND "configurations"."configurations"."deleted_at" IS NULL) OR (("configurations"."configurations"."website_id" IN (7, 12, 10, 5, 8, 2, 9, 11, 3, 1, 4, 6) AND "configurations"."configurations"."deleted_at" IS NULL) OR (("configurations"."configurations"."user_id" = 1 AND "configurations"."configurations"."website_id" = 1 AND "configurations"."configurations"."deleted_at" IS NULL) OR ("configurations"."configurations"."user_id" = 1 AND "configurations"."configurations"."website_id" = 1 AND "configurations"."configurations"."deleted_at" IS NULL)))) AND "configurations"."configurations"."archived_at" IS NULL AND ( configurations.configurations.glass_mounting_type = 'rm_gm') AND ( configurations.configurations.display_mounting_type = 'mws') AND "configurations"."configurations"."configurable" = $1 AND ( configurations.configurations.display-id = '738') ORDER BY "configurations"."configuration_id" DESC LIMIT $2 OFFSET $3  [["configurable", true], ["LIMIT", 20], ["OFFSET", 0]]

The column name in the query is configurations.configurations.display-id and not "configurations"."configurations"."display-id".
If I copy the query in PgAdmin and I execute it with the quotes applied, it's fine.
I think it should be changed the way the column name is generated by wice_grid to handle this case.
I digged into the code, but not enough yet to have a solution.

Current behaviour

I get an error:

PG::UndefinedColumn: ERRORE:  la colonna configurations.display non esiste
LINE 1: ...tions"."configurations"."configurable" = $1 AND ( configurat...
                                                             ^
HINT:  Forse intendevi referenziare la colonna "configurations.display-id".

That means the column "configurations.display" and maybe I wanted to reference the "configurations.display-id".

Expected behaviour

I get the filtered results page.

Thank you for your support!

@afdev82 afdev82 changed the title Postgres column name with "-" not handled correctly Postgres column name with "-" not correctly handled Apr 12, 2022
afdev82 added a commit to adnotam/wice_grid that referenced this issue Oct 24, 2024
afdev82 pushed a commit to adnotam/wice_grid that referenced this issue Oct 24, 2024
Only call group when there actually is a group set in WiceGrid#read relation

This fixes a bug with wrong paginated result set when having a wice_grid with
an include or column with assoc option on a many association. If this is the
case the grid tries to eager load this association (due to the include/references
on the relation). Rails then normally gets the correct page set by performing an
additonal query to get the matching IDs without the eager load, however this
functionality is disabled when there is a group set on the relation. Because
WiceGrid always called group even when there was no group set this behaviour was
always disabled, leading to an incorrect page set.

By only calling group when there actually is a group we fix this problem in most
cases. However, when providing a group to the grid, problems still occur, but so
does providing a group to a relation with eager load in PostgreSQL in Rails
itself already (e.g. `Author.eager_load(:books).group(:id)`). It might be better
to never eager load associations, but instead always preload them and add the
sort/filter conditions using a left_joins (in combination with a distinct to get
each main model only once).

Also return Arel in get_custom_order_reference when custom order is SqlLiteral

Fixes 'Query method called with non-attribute argument(s)' when using Arel.sql
for custom order in combination with Ruby 3. Should already have been fixed when
the deprecation warning was fixed, but apparently it was not.

Fixup c7a9da2

fix for issue patricklindsay#82
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

No branches or pull requests

1 participant