thoughtbot / thoughtbot/factory_bot
Updating from 6.2.0 -> 6.4.2 is a breaking change for us: "Do not define "id". Instead, rely on the database to generate it."
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 8.2k
- Forks
- 2.6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
We are modeling tree structures in with UUID primary keys. We specifically chose UUID as type because among other benefits we can generate those IDs in the application and send whole trees to the database in a single transaction without having to go back and forth for each new node we are inserting.
Reproduction Steps
We have this factory:
factory :root_node, class: 'Tree' do
id { SecureRandom.uuid }
root_id { id }
end
Expected behavior
The instance should be constructed with identical values for id and root_id (as was the case with FactoryBot 6.2.0). Alternatively we would be fine with overriding this behavior but browsing the Readme or the web for "Do not define "id". Instead, rely on the database to generate it." didn't yield any helpful results.
Actual behavior
Creating instances worked just fine with FactoryBot 6.2.0, but since at latest 6.4.2 this results in the following error:
FactoryBot::AttributeDefinitionError:
Attribute generates "id" primary key for Tree"
Do not define "id". Instead, rely on the database to generate it.
System configuration
factory_bot version: 6.4.2
rails version: 7.0.8
ruby version: 3.2.2
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 the reported factory definition and compare its behavior between FactoryBot 6.2.0 and 6.4.2 under Rails 7.0.8 and Ruby 3.2.2. Trace the handling of the generated id and the dependent root_id value, then verify that the documented or restored behavior matches the expected UUID values without triggering the AttributeDefinitionError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rails, ruby
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100