Shopify / Shopify/tapioca

ActiveModel::Attribute generates non nilable attribute that should be nilable

Open
#2,277 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Ruby
Stars
873
Forks
164
Avg merge
4d 27m
Merged PRs (30d)
9

Description

I have the following class (whole content):

# app/models/vacancy.rb

# typed: true
# frozen_string_literal: true

class Vacancy < ApplicationRecord
  attribute :startlatest, :datetime
end

I generates the DSL to have a non nilable startlatest:

# sorbet/rbi/dsl/vacancy.rbi

class Vacancy
  include GeneratedAttributeMethods
  # [...]

  private

  module GeneratedAttributeMethods
    # [...]

    sig { returns(::ActiveSupport::TimeWithZone) }
    def startlatest; end

    sig { params(value: ::ActiveSupport::TimeWithZone).returns(::ActiveSupport::TimeWithZone) }
    def startlatest=(value); end

    # [...]
  end
end

Why does it assume the attribute is not nilable in this case? Shouldn't it be nilable?

Tapioca v0.16.11

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduction in app/models/vacancy.rb and compare it with the generated sorbet/rbi/dsl/vacancy.rbi output. Trace how the attribute DSL determines the getter and setter types, then verify that a datetime attribute without a value produces nullable signatures in the generated RBI.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.