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

st_buffer usage of to_f causes error when building the query with Arel: Unsupported argument type: Float. Construct an Arel node instead #82

Open
Buk1m opened this issue Dec 12, 2024 · 1 comment

Comments

@Buk1m
Copy link

Buk1m commented Dec 12, 2024

Issue description

Error caused by the distance.to_f within the RGeo::ActiveRecord::SpatialExpressions.st_buffer function

spatial_expressions.rb#L125

Reproduction

With ActiveRecord 7+ prepare a query using Arel with st_buffer(100) and call to_sql on it.

Error

Unsupported argument type: Float. Construct an Arel node instead.

Context

https://github.com/rails/rails/blob/v7.0.8.5/activerecord/lib/arel/visitors/to_sql.rb#L770

Solution?

As there is no visitor for the Float type it should expect that the consumer will provide proper Arel.sql node as an argument instead of a number.
Either remove the to_f or rewrap it into Arel.sql (could hide errors when invalid value was provided).

Environment:

gems/rgeo-3.0.1
gems/rgeo-activerecord-7.0.1
gems/activerecord-7.0.8.5
gems/rails-7.0.8.5
ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [arm64-darwin22]
@Buk1m Buk1m changed the title st_bugger using to_f does causes error when building the query with arel: Unsupported argument type: Float. Construct an Arel node instead st_buffer using to_f does causes error when building the query with arel: Unsupported argument type: Float. Construct an Arel node instead Dec 12, 2024
@Buk1m Buk1m changed the title st_buffer using to_f does causes error when building the query with arel: Unsupported argument type: Float. Construct an Arel node instead st_buffer using to_f causes error when building the query with arel: Unsupported argument type: Float. Construct an Arel node instead Dec 12, 2024
@Buk1m Buk1m changed the title st_buffer using to_f causes error when building the query with arel: Unsupported argument type: Float. Construct an Arel node instead st_buffer usage of to_f causes error when building the query with Arel: Unsupported argument type: Float. Construct an Arel node instead Dec 12, 2024
@Buk1m
Copy link
Author

Buk1m commented Dec 12, 2024

Similar issue with the units.to_s on the next line

either it should expected an Arel::Nodes::SqlLiteral without calling the to_s
or the spatial_flags should be [true, true, true] as this is the only path that supports visiting String.

Am I using an incorrect version of the library? I would assume such issues would be quickly reported/discovered.

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