I started to work in a legacy project and if I try to find a cequel record and then convert it to yaml:
fj = FullJob.find(1)
fj.to_yaml
I'm getting a stack level too deep
error.
Checking deeper, there's a @record_collection
instance variable defined in the cequel record, which it brings a copy of the same object and inside of this, another copy of the same and so on...:
[7] pry(main)> fj.instance_variables
=> [:@record_collection, :@cequel_attributes, :@collection_proxies, :@loaded, :@persisted]
[8] pry(main)> fj.instance_variable_get(:@record_collection)
=> [#<FullJob id: 1, #...
[9] pry(main)> fj.instance_variable_get(:@record_collection).first.instance_variable_get(:@record_collection)
=> [#<FullJob id: 1, #...
The problem is, the ruby yaml parser, at some point, tries to parse all the instance variables of an object, which eventually derives in the mentioned SystemStackError
.
Worth to mention this is only happening in this specific model, I mean, as far as I've seen, the @record_collection
variable comes nil
for another cequel models present in this project.
Not sure at all how this works, if this is a cequel bug or something not properly configured in the model, but... maybe has to do with cequel lazy loading?, anyway I'm running out of ideas here :(