luckyframework / luckyframework/avram
Nested preloads seem to fail
Nobody has claimed this yet.
- Dominant language
- Crystal
- Stars
- 183
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
This one is strange, and could be just me doing something wrong. If that's the case, then we can close this issue out.
In the Avram spec suite, [these](https://github.com/luckyframework/avram/blob/master/spec/support/product.cr) [models](https://github.com/luckyframework/avram/blob/master/spec/support/line_item.cr) [exist](https://github.com/luckyframework/avram/blob/master/spec/support/price.cr). If you add this spec in to master branch, it will fail:
```crystal
it "preloads nested" do
Avram.temp_config(lazy_load_enabled: false) do
item = LineItemBox.create
price = PriceBox.create &.line_item_id(item.id).in_cents(500)
product = ProductBox.create
LineItemProductBox.create &.line_item_id(item.id).product_id(product.id)
products = Product::BaseQuery.new
.preload_line_items
# notice the preload_price here
.where_line_items(LineItem::BaseQuery.new.preload_price)
products.first.line_items.first.price.as(Price).in_cents.should eq(500)
end
end
```
This fails with:
> price for LineItem must be preloaded with 'preload_price' (Avram::LazyLoadError)
I originally thought this was related to the [clone](https://github.com/luckyframework/avram/commit/65c28b4225eb5d129223253172ed46f2bf4160e8) commit, but if you look at the spec, you'll see there's no mention of clone being used.
To test this theory:
* Add spec to current master branch. Run spec with:
`DATABASE_URL=postgres://postgres@localhost:5432/avram_dev crystal spec spec/query_spec.cr:630`
* Watch spec fail
* remove spec and ensure repo is clean
* `git checkout a8112f3b0abca05c06da0c3ba3f599dc6b06110b`
* Add spec to this branch, and run spec
* Watch spec fail
This resets the codebase to before crystal 0.30 support was added, and the spec still fails. My conclusion here is that either this level of nested preloads is missing something, or my spec code is wrong.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproduction in spec/query_spec.cr:630 and the linked Product, LineItem, and Price model files under spec/support. Run DATABASE_URL=postgres://postgres@localhost:5432/avram_dev crystal spec spec/query_spec.cr:630, then compare behavior at the referenced commit. Done means the nested preload case has an agreed expected behavior and either passes without LazyLoadError or the spec is shown to be invalid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- crystal, postgres
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100