-
-
Notifications
You must be signed in to change notification settings - Fork 592
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
Saving record with save(validate: false)
skips generating slug, sometimes
#947
Comments
Thanks @vfonic can you please post a minimal reproduction case, or test case? |
@parndt here's the minimal repro case: It's on this branch on my fork (just 1 commit): Here's the output of running the tests:
Note that the second test (when calling |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
@parndt did you have any chance to look into this one? I don't want this issue to get closed because it's "stale". Thanks! 🙏 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
@parndt I rebased on top of the Going through the code, this line seems to be the issue: model_class.before_validation :set_slug The slug is only set if validation occurs. So if you do I'm not sure what would be the best way around this. Here's the list of callbacks executed:
I played around with
I've found out that if we make this change, all the tests pass: model_class.before_validation :set_slug
+ model_class.before_save :set_slug
model_class.after_validation :unset_slug_if_invalid We still need to keep Even though all of the tests pass, I'm not sure if this is the best solution. Someone who knows the project better might find some edge cases that are not covered by tests that might break. Maybe there's a case where we don't want to generate slug. The good news is that @parndt what do you think? |
Thank you, Philip! 👍 |
I just discovered an issue that happened in my app.
When I call
record.save!(validate: false)
on a record, it doesn't generate slug for it.However, if I call
record.valid?
before callingrecord.save!(validate: false)
, it does generate the slug.This is what made me miss this issue at first.
I believe this could be a bug within the friendly_id gem.
The text was updated successfully, but these errors were encountered: