luckyframework / luckyframework/avram
Avoid this query pattern and avoid crashing your app
Nobody has claimed this yet.
- Dominant language
- Crystal
- Stars
- 183
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
I've done this before, and just did it again which leads to this fun error:

When you have a query object, and you create a method named the same as a column of that model, you'll blow things up if you try to order on that "method".
class TaskQuery < Task::BaseQuery
def active
active(true)
end
end
# returns all tasks that are active. Works great!
TaskQuery.new.active
# Try to sort where the active ones are first, but cause infinite recursion and tank your system
TaskQuery.new.active.asc_order
Maybe we can somehow catch that if you define a method named the same as a column name, it throws a compile-time error? I think there's a method_added macro https://crystal-lang.org/reference/1.7/syntax_and_semantics/macros/hooks.html
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 TaskQuery example, the query column/method handling, and Crystal's method_added macro hook documentation. Determine how a method such as active collides with a column when asc_order is called, then establish whether the intended completion is a compile-time diagnostic or another guard against recursion. Done should include coverage for the shown query pattern and prevent the application crash.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- crystal
- Domain
- database
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100