thoughtbot / thoughtbot/factory_bot
build_stubbed does not fill id for uuid column type with SQLServer
Nobody has claimed this yet.
- 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.
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
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.
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