model
model copied to clipboard
Error: missing attributes in ROM::Relation
Hey. I'm getting this error as part of my model: Hanami::Model::Error: missing attributes in ROM::Relation::Name(commits) schema: :payload
. I think I'm doing everything right, but maybe not?
# migration
Hanami::Model.migration do
change do
create_table :commits do
# other stuff
column :payload, :longtext, null: false
end
end
end
# model
class Commit < Hanami::Entity
attributes do
attribute :payload, Types::String
end
end
The error backtraces to hanami/model/config line 134. I just tried deleting the payload
field from the table, and it works again.
Is there something actually wrong here, or did I make a mistake?
Update: I added a proof of concept of this at https://github.com/greggilbert/hanami-model-416.
As discussed in the Chat on July 24, 2017 10:05 AM, the probable cause is that rom-sql does not support mysql types.
@greggilbert @kaikuchn I debugged the problem, this rom-sql
method is responsible to build a ROM type for each attribute, but it fails because Sequel doesn't return a "ruby type" for MySQL's :longtext
.
(byebug) type
nil
(byebug) db_type
"longtext"
(byebug) rest
{:default=>nil, :ruby_default=>nil}
Because of that lacking information, ROM skips that column/attribute.
@flash-gordon @solnic Does it makes sense to have a fallback to string instead to ignore the column?
I'd say we should raise an error, as in, we should not infer an attribute when ruby type is nil, then you'll get an 'attribute missing error' and you'll know you need to define it manually.
I changed the error message in 4.0 btw https://github.com/rom-rb/rom/blob/7ed4ad8b030210692bc850ae8fbf3e293922b9e1/core/lib/rom/schema/inferrer.rb#L12-L19
Hey guys, I ran the PoC that @greggilbert provided, but changed the ruby version to 2.7.7 and this error persists. Also, I checked the gemspec of hanami-model
and the ROM dependency points to "~> 3.3", ">= 3.3.3"
, so the fix that @flash-gordon made won't be applied.
So I was wondering if this issue/bug is still valid, and if I could work on it
@kaikuchn @jodosha Hey, it's been a while. I want to check with you if this is an active bug, and if so, can we bump the dependency of hanami-model
to use the newer version with the error message, available in 4.0? Or, this issue is solved according to the chat, and can we close it?
I just helped @greggilbert to debug the issue, so I don't know if it is an active bug. Bumping the dependency of Hanami-Model to ROM 4.0 would be nice but I don't think it's feasible without breaking changes to Hanami-Model.
Anyway, since there is a working solution to this problem, I think we can close this issue! :)