Shopify / Shopify/tapioca

Incorrect array signature for `.new` in ActiveRecord model

Open
#1,981 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

An incorrect signature is being generated for the .new method in an ActiveRecord model.

Even though the .new method does not support arrays, this signature is nevertheless being generated:

    sig do
      params(
        attributes: T::Array[T.untyped],
        block: T.nilable(T.proc.params(object: ::Payment).void)
      ).returns(T::Array[::Payment])
    end

This is despite arrays not being supported in the .new method:

[1] > Payment.new([])
ArgumentError: When assigning attributes, you must pass a hash as an argument, Array passed.

Suspect commit: https://github.com/Shopify/tapioca/pull/1946/files#diff-ccd1794e49448cc1badb48d2a32af60d5fcd47336d00a484fbf474ebf79b6789R223

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 by reviewing the linked Shopify/tapioca pull request, especially the referenced diff near line 223, and reproduce the reported Payment.new([]) behavior. Trace how that behavior is reflected in the generated signature. Done means the generated .new signature no longer advertises array attributes or an array return for this case.

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
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.