ActiveRecored::RecordNotUnique in bulk `invite!`
Potentially this is a regression in this or a related gem?
Working on functionality around uploading a CSV and invite!-ing users I'm seeing:
ActiveRecord::RecordNotUnique Mysql2::Error: Duplicate entry '129332' for key 'users.PRIMARY'
The code effectively looks like:
User.invite!({ email: email, name: name }, inviting_user) do |u|
u.skip_invitation = true
u.skip_confirmation_notification!
end
For ~1600 users in a loop, though it seems to hit the duplicate almost immediately. Creating the users beforehand and then inviting them separately appears to work around this issue.
Environment
DeviseInvitable 2.0.10 Devise 4.9.4 MySQL 8.0.40 Rails 7.0.8.7 Ruby 3.3.5
Potentially this is a regression in this or a related gem?
Working on functionality around uploading a CSV and
invite!-ing users I'm seeing:ActiveRecord::RecordNotUnique Mysql2::Error: Duplicate entry '129332' for key 'users.PRIMARY'The code effectively looks like:
User.invite!({ email: email, name: name }, inviting_user) do |u| u.skip_invitation = true u.skip_confirmation_notification! endFor ~1600 users in a loop, though it seems to hit the duplicate almost immediately. Creating the users beforehand and then inviting them separately appears to work around this issue.
Environment
DeviseInvitable 2.0.10 Devise 4.9.4 MySQL 8.0.40 Rails 7.0.8.7 Ruby 3.3.5
Make sure config.validate_on_invite = true is enabled. However the drawback is that you will be forced to provide a password when inviting record. This is weirdly done.
Edit
Analyzing the source code, it seems to simply be an inconsistent behavior
User.new(**params).invite! -> requires password
User.invite!(**params) -> doesn't require password, it assigns a random one automatically
Make sure config.validate_on_invite = true is enabled
I'm not sure I'm following - to what end? Are you saying something about that configuration would fix the primary key values?
Make sure config.validate_on_invite = true is enabled
I'm not sure I'm following - to what end? Are you saying something about that configuration would fix the primary key values?
The other day I though the exception was caused by an SQL unique index that was triggered. This usually happens when valuations are skipped. However reading the exception this morning, I realize this is not what is happening, sorry about that.