NoMethodError: undefined method `gsub' for #<ULID::Rails::Type::Data:0x000000010d9b6258 @value="\x01\x81\xD0@\xC0\xAAaO\x9D\xF9+\x0FZ\xE3VS">
Closed this issue · 4 comments
gjtorikian commented
I am not sure why, but when I try to iterate over a collection of records with ULIDs as primary keys, an error is thrown:
>> type
=> #<ULID::Rails::Type:0x00000001086251c0 @formatter=ULID::Rails::Formatter, @validator=ULID::Rails::Validator, @precision=nil, @scale=nil, @limit=nil>
>> value
=> #<ULID::Rails::Type::Data:0x000000010d9b6258 @value="\x01\x81\xD0@\xC0\xAAaO\x9D\xF9+\x0FZ\xE3VS">
>> type.serialize(value)
NoMethodError: undefined method `gsub' for #<ULID::Rails::Type::Data:0x000000010d9b6258 @value="\x01\x81\xD0@\xC0\xAAaO\x9D\xF9+\x0FZ\xE3VS">
string.gsub(/-/,'').upcase
Stack trace:
[base32-crockford (0.1.0) lib/base32/crockford.rb:130:in `clean' ]
[base32-crockford (0.1.0) lib/base32/crockford.rb:99:in `decode' ]
[ulid-rails (1.0.0) lib/ulid/rails/formatter.rb:12:in `unformat' ]
[ulid-rails (1.0.0) lib/ulid/rails/type.rb:40:in `serialize' ]
[activemodel (7.0.3) lib/active_model/attribute.rb:56:in `value_for_database' ]
[activerecord (7.0.3) lib/active_record/connection_adapters/abstract/quoting.rb:209:in `block in type_casted_binds' ]
[activerecord (7.0.3) lib/active_record/connection_adapters/abstract/quoting.rb:207:in `map' ]
[activerecord (7.0.3) lib/active_record/connection_adapters/abstract/quoting.rb:207:in `type_casted_binds' ]
[activerecord (7.0.3) lib/active_record/connection_adapters/postgresql_adapter.rb:765:in `exec_no_cache' ]
[activerecord (7.0.3) lib/active_record/connection_adapters/postgresql_adapter.rb:745:in `execute_and_clear' ]
[activerecord (7.0.3) lib/active_record/connection_adapters/postgresql/database_statements.rb:54:in `exec_query' ]
[activerecord (7.0.3) lib/active_record/connection_adapters/abstract/database_statements.rb:560:in `select' ]
[activerecord (7.0.3) lib/active_record/connection_adapters/abstract/database_statements.rb:66:in `select_all' ]
[activerecord (7.0.3) lib/active_record/connection_adapters/abstract/query_cache.rb:107:in `block in select_all' ]
[activerecord (7.0.3) lib/active_record/connection_adapters/abstract/query_cache.rb:137:in `block in cache_sql' ]
[activesupport (7.0.3) lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt' ]
[activesupport (7.0.3) lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize' ]
[activesupport (7.0.3) lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt' ]
[activesupport (7.0.3) lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize' ]
[activerecord (7.0.3) lib/active_record/connection_adapters/abstract/query_cache.rb:128:in `cache_sql' ]
[activerecord (7.0.3) lib/active_record/connection_adapters/abstract/query_cache.rb:107:in `select_all' ]
[activerecord (7.0.3) lib/active_record/querying.rb:54:in `_query_by_sql' ]
[activerecord (7.0.3) lib/active_record/relation.rb:941:in `block in exec_main_query' ]
[activerecord (7.0.3) lib/active_record/relation.rb:961:in `skip_query_cache_if_necessary' ]
[activerecord (7.0.3) lib/active_record/relation.rb:927:in `exec_main_query' ]
[activerecord (7.0.3) lib/active_record/relation.rb:913:in `block in exec_queries' ]
[activerecord (7.0.3) lib/active_record/relation.rb:961:in `skip_query_cache_if_necessary' ]
[activerecord (7.0.3) lib/active_record/relation.rb:907:in `exec_queries' ]
[activerecord (7.0.3) lib/active_record/relation.rb:695:in `load' ]
[activerecord (7.0.3) lib/active_record/associations/preloader/association.rb:39:in `load_records_for_keys' ]
[activerecord (7.0.3) lib/active_record/associations/preloader/association.rb:75:in `load_records' ]
[activerecord (7.0.3) lib/active_record/associations/preloader/association.rb:54:in `records' ]
[activerecord (7.0.3) lib/active_record/associations/preloader/association.rb:26:in `records_for' ]
[activerecord (7.0.3) lib/active_record/associations/preloader/association.rb:30:in `load_records_in_batch' ]
[activerecord (7.0.3) lib/active_record/associations/preloader/batch.rb:42:in `block in group_and_load_similar' ]
[activerecord (7.0.3) lib/active_record/associations/preloader/batch.rb:41:in `each_pair' ]
[activerecord (7.0.3) lib/active_record/associations/preloader/batch.rb:41:in `group_and_load_similar' ]
[activerecord (7.0.3) lib/active_record/associations/preloader/batch.rb:27:in `call' ]
[activerecord (7.0.3) lib/active_record/associations/preloader.rb:118:in `call' ]
[activerecord (7.0.3) lib/active_record/relation.rb:829:in `block in preload_associations' ]
[activerecord (7.0.3) lib/active_record/relation.rb:828:in `each' ]
[activerecord (7.0.3) lib/active_record/relation.rb:828:in `preload_associations' ]
[activerecord (7.0.3) lib/active_record/relation.rb:917:in `block in exec_queries' ]
[activerecord (7.0.3) lib/active_record/relation.rb:961:in `skip_query_cache_if_necessary' ]
[activerecord (7.0.3) lib/active_record/relation.rb:907:in `exec_queries' ]
[activerecord (7.0.3) lib/active_record/association_relation.rb:44:in `exec_queries' ]
[activerecord (7.0.3) lib/active_record/relation.rb:695:in `load' ]
[activerecord (7.0.3) lib/active_record/relation.rb:250:in `records' ]
[activerecord (7.0.3) lib/active_record/relation/delegation.rb:88:in `each' ]
app/views/shared/_inbox_convo_sidebar.html.erb:63
gjtorikian commented
@k2nr any ideas here?
gjtorikian commented
Further debugging shows that this is caused by an includes
:
>> @router.conversations.where(state: Conversation::STATE_OPEN).order("number DESC").limit(50)
=> #<ActiveRecord::AssociationRelation [#<Conversation id: "01G7841G5AC57SVY9B1XDE6NJK", title: "It is impossible to begin to learn that which one ...", state: "open", created_at: "2022-07-04 21:25:13.513134000 +0000", updated_at: "2022-07-05 21:25:13.513324000 +0000", messages_count: 1, number: 250, assignee_ids: [], label_ids: [], router_id: "01G7841D33CQW8W4RBC7BNZP65">, , ...]>
>> @router.conversations.where(state: Conversation::STATE_OPEN).order("number DESC").limit(50).includes(:messages)
NoMethodError: undefined method `gsub' for #<ULID::Rails::Type::Data:0x0000000126a170a8 @value="\x01\x81\xD0@\xC0\xAAaO\x9D\xF9+\x0FZ\xE3VS">
string.gsub(/-/,'').upcase
^^^^^
gjtorikian commented
Sorry for the noise! I fixed the problem like this:
has_many :messages, dependent: :destroy, primary_key: :ulid # add `primary_key: :ulid`
This is on Rails 7 BTW. Not sure why it's necessary but there it is.
bquorning commented
Hi @gjtorikian. I think this is fixed by f875368 in v1.1.0. Feel free to open a new issue if that is not the case, and I will try to help with isolating the reproduction steps.