thoughtbot / thoughtbot/factory_bot

build_stubbed does not fill id for uuid column type with SQLServer

Open
#1,618 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Ruby
Stars
8.2k
Forks
2.6k
PR merge metrics
No merged PRs in 30d

Description

Description

When using SQLServer and 'uuid' as the primary key type, they 'build_stubbed' method does not automatically fill the id column. I would assume that this is filled independent of the column type.

https://github.com/thoughtbot/factory_bot/blob/0521d914974f6fecf5a3f77b60a86ae4f057f787/lib/factory_bot/strategy/stub.rb#L91-L96
I'm thinking the code here is the problem.

image

In SQLServer, the column.sql_type seems to be "uniqueidentifier".
I think it might work if I use column.type, but I don't know if this is a problem in other databases, so I've raised an issue.

Reproduction Steps

Sample code → https://github.com/vividmuimui/sqlserver-factorybot/commits/main/

Expected behavior

When you use build_stubbed, the primary key is always set. Also if you use the uuid type.

Actual behavior

The id of the generated instance is nil.

System configuration

factory_bot version: 6.4.5
rails version: 7.1.3
ruby version: v3.3.0

Contributor guide

Open the contributing guide

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 lib/factory_bot/strategy/stub.rb around lines 91-96 and reproduce the issue using the sample project linked in the report. Compare how the SQLServer column type is handled with other primary-key types. Done means build_stubbed assigns a non-nil primary key for UUID columns without breaking other database adapters.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
databases, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.