luckyframework / luckyframework/avram

Primary key methods that are overridden can raise exceptions

Open
#568 3 comments 0 reactions 0 assignees View on GitHub
improve error experience
Dominant language
Crystal
Stars
183
Forks
67
PR merge metrics
No merged PRs in 30d

Description

Take a look at this example: https://play.crystal-lang.org/#/r/a4y0

If you override one of the primary key methods to do your own deal, like in this example, you'll run in to a compile-time error when you wouldn't expect it.

The idea here was basically doing a custom delete where it was expected to basically delete the current model, and delete another model.

In any case, the fix for this is to add `include Avram::PrimaryKeyMethods` to the `Base` model, and things are fine. I don't think this is something we need to patch because it's sort of an edge case that you'd define your own version of one of these methods when they're already included; however, I think we can work out the error message a little nicer to maybe give the user a heads up that they can include this module if they need.

Contributor guide

Open the contributing guide

Research direction

Start with the linked Crystal playground reproduction and inspect how overriding a primary-key method on the Base model produces the compile-time error. Trace the PrimaryKeyMethods inclusion and update the diagnostic so it explains that including Avram::PrimaryKeyMethods can restore the default behavior; confirm the reproduction no longer gives an unexplained error.

Written by the indexing model from the issue text.

Assessment

Tech stack
crystal
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.