RBI: getter methods on belongs_to associations have returns(T.nilable(...)) as sig but belongs_to reflection is not optional
Maintainers usually reply within 3 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- ruby
- Domain
- developer-experience, tooling
Research direction
Start with Tapioca::Dsl::Compilers::ActiveRecordAssociations#populate_single_assoc_getter_setter and inspect how belongs_to reflection options determine the generated getter return type. Compare generated RBIs for optional and non-optional belongs_to associations, then verify that only the non-optional case avoids nilable typing.
Written by the indexing model from the issue text.
Description
I noticed the returns signature of any belongs_to association on a model is always nilable in the RBI file, even if the belongs_to is not optional. Rails will raise an error if a nil value is present for such an association. I don't find it optimal to add T.must everywhere to change this in application code.
I changed Tapioca::Dsl::Compilers::ActiveRecordAssociations#populate_single_assoc_getter_setter and it seems to work:
association_type = if !reflection.options[:optional] && reflection.is_a?(ActiveRecord::Reflection::BelongsToReflection)
association_class
else
as_nilable_type(association_class)
end
What do you think ?
- Dominant language
- Ruby
- Stars
- 874
- Forks
- 165
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 10
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing 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.
More from Shopify/tapioca
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Shopify/tapioca#2662 · 1 comment ·
Maintainers usually reply within 3 days
-
Improve `check-shims` performancePossibly taken @KaanOzkan claimed this 4 days ago. Open
Shopify/tapioca#2728 · 1 assignee ·
Maintainers usually reply within 3 days
-
ActiveRecordRelations cannot generate an RBI for an Active Record model with a composite primary keyPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 3/5 1-2 days Newbie friendliness 76/100
Maintainers usually reply within 3 days
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
Maintainers usually reply within 3 days
-
Prepending a module can cause `tapioca dsl` to produce an untyped signaturePossibly taken @KaanOzkan claimed this 40 days ago. Openbug
Shopify/tapioca#2705 · 1 assignee ·
Maintainers usually reply within 3 days
Similar issues
-
security
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
grafana/pyroscope#5729 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
rubygems/rubygems.org#6895 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
samvera/hyku#3359 · 1 comment ·
Maintainers usually reply within 1 day
-
Child factories do not inherit traits from their parentPossibly taken @alassek claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
rom-rb/rom-factory#99 ·