rom-sql
rom-sql copied to clipboard
Inclusion filtering does not work on enum type table columns
Describe the bug
I have a postgres enum called status_type with string values, and I used it to set the column type on a column in a table. I want to filter by inclusion on it: root.where(root[:status].in('requested')), and it returns a dry-types constraint error:
Dry::Types::ConstraintError: ["requested"] violates constraints (included_in?(["requested", "approved"], ["requested"]) failed)
It's weird because if I filter by equality it works ok. root.where(root[:status].is('requested'))
As a workaround I defined the attribute with type string in the relation schema and now it works.
To Reproduce
- create a postgres enum containing strings
- create a table and set a column with type of that enum
- use an relation with inferred schema
- try to filter on it using
inoperator - see the error
Dry::Types::ConstraintError:
["requested"] violates constraints (included_in?(["requested", "approved", "system_rejected", "denied"], ["requested"]) failed)
# /bundle/ruby/2.6.0/gems/dry-types-1.3.1/lib/dry/types/constrained.rb:43:in `call_unsafe'
# /bundle/ruby/2.6.0/gems/dry-types-1.3.1/lib/dry/types/enum.rb:42:in `call_unsafe'
# /bundle/ruby/2.6.0/gems/dry-types-1.3.1/lib/dry/types/type.rb:49:in `call'
# /bundle/ruby/2.6.0/gems/rom-sql-3.2.0/lib/rom/sql/attribute.rb:402:in `binary_operation_arg'
# /bundle/ruby/2.6.0/gems/rom-sql-3.2.0/lib/rom/sql/attribute.rb:391:in `__cmp__'
# /bundle/ruby/2.6.0/gems/rom-sql-3.2.0/lib/rom/sql/attribute.rb:239:in `in'
# ./lib/persistence/concerns/filtering.rb:23:in `in'
# ./lib/persistence/concerns/filtering.rb:38:in `public_send'
# ./lib/persistence/concerns/filtering.rb:38:in `block (2 levels) in with_filter'
# ./lib/persistence/concerns/filtering.rb:35:in `each'
# ./lib/persistence/concerns/filtering.rb:35:in `reduce'
# ./lib/persistence/concerns/filtering.rb:35:in `block in with_filter'
# ./lib/persistence/concerns/filtering.rb:33:in `each'
# ./lib/persistence/concerns/filtering.rb:33:in `reduce'
# ./lib/persistence/concerns/filtering.rb:33:in `with_filter'
# /bundle/ruby/2.6.0/gems/rom-core-5.2.1/lib/rom/pipeline.rb:67:in `method_missing'
# ./lib/api/requests/repositories/request.rb:51:in `filter'
# ./spec/lib/api/requests/repositories/request_spec.rb:17:in `block (4 levels) in <top (required)>'
# ./spec/lib/api/requests/repositories/request_spec.rb:67:in `block (3 levels) in <top (required)>'
# ./spec/db_spec_helper.rb:32:in `block (3 levels) in <top (required)>'
# /bundle/ruby/2.6.0/gems/database_cleaner-1.8.3/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/transaction.rb:36:in `block in cleaning'
# /bundle/ruby/2.6.0/gems/sequel-5.28.0/lib/sequel/database/transactions.rb:251:in `_transaction'
# /bundle/ruby/2.6.0/gems/sequel-5.28.0/lib/sequel/database/transactions.rb:233:in `block in transaction'
# /bundle/ruby/2.6.0/gems/sequel-5.28.0/lib/sequel/connection_pool/threaded.rb:92:in `hold'
# /bundle/ruby/2.6.0/gems/sequel-5.28.0/lib/sequel/database/connecting.rb:270:in `synchronize'
# /bundle/ruby/2.6.0/gems/sequel-5.28.0/lib/sequel/database/transactions.rb:199:in `transaction'
# /bundle/ruby/2.6.0/gems/database_cleaner-1.8.3/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/transaction.rb:36:in `cleaning'
# /bundle/ruby/2.6.0/gems/database_cleaner-1.8.3/lib/database_cleaner/configuration.rb:87:in `block (2 levels) in cleaning'
# /bundle/ruby/2.6.0/gems/database_cleaner-1.8.3/lib/database_cleaner/configuration.rb:88:in `cleaning'
# ./spec/db_spec_helper.rb:25:in `block (2 levels) in <top (required)>'
Expected behavior
- it should filter the resources based on the given value in the filter
Your environment
- Affects my production application: NO
- Ruby version: ruby 2.6.2
- OS: Linux
Zulip conversation link here