Shopify / Shopify/tapioca

Incorrect return type for ActiveRecord encrypted hashes

Open
#2,631 1 comment 1 reaction 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

Bit of an edge case, but:

class MyModel < ApplicationRecord
  serialize :secret_hash, type:Hash, coder: JSON
  encrypts :secret_hash
end

results in the following signatures:

class MyModel
    sig { returns(::String) }
    def secret_hash; end

    sig { params(value: ::String).returns(::String) }
    def secret_hash=(value); end
end

which makes sense since secret_hash is a string in the DB schema (due to being encrypted), but the type for the accessors should be T::Hash[T.untyped, T.untyped].

I can take a stab at a PR if this is something that would be accepted into Tapioca.

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 reproducing the MyModel example and inspecting the generated RBI signatures for the encrypted serialized hash. Trace how Tapioca derives accessor types from serialize and encrypts; done when both accessors use T::Hash[T.untyped, T.untyped] and the relevant behavior is covered by tests.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.