-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build_stubbed
does not fill id
for uuid
column type
#1498
Comments
Thanks for opening an issue @StefSchenkelaars . We did some exploration and it seems like an issue with the type of the column. This could be something we support, but the assumption made to auto-generate the As a workaround, you could specify the id when the value is built, or you can try adding it on your factory definition. post = FactoryBot.build_stubbed(:uuid_post, id: SecureRandom.uuid)
# Or on the definition
factory :uuid_post do
id { SecureRandom.uuid }
body { "Post body" }
end I think a first action we could take is to add a note on the GETTING_STARTED.md doc, mentioning that the primary key stub only works for numeric primary keys. |
A third workaround if you have a number of models with uuids, create a global trait # frozen_string_literal: true
# Temporary workaround for https://github.com/thoughtbot/factory_bot/issues/1498 until https://github.com/thoughtbot/factory_bot/pull/1583 is released.
# Once #1583 is released, remove this trait and use build_stubbed directly.
FactoryBot.define do
trait :with_id do
id { SecureRandom.uuid }
end
end |
Description
When using
uuid
as the primary key type, theybuild_stubbed
method does not automatically fill theid
column. I would assume that this is filled independent of the column type.Reproduction Steps
Reproduction script
Expected behavior
When you use
build_stubbed
, the primary key is always set. Also if you use theuuid
type.Actual behavior
The
id
of the generated instance isnil
.System configuration
factory_bot version:
6.2.0
rails version:
6.1.3.2
ruby version:
3.0.1
The text was updated successfully, but these errors were encountered: