Skip to content
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

Suggestion: Option to raise error when record has non-enumerized value? #453

Open
jzisser9 opened this issue Jul 8, 2024 · 0 comments
Open

Comments

@jzisser9
Copy link

jzisser9 commented Jul 8, 2024

TLDR: A configuration option to cause Enumerize to raise an error when a record with an invalid enumerized attribute would be very helpful!


Hello! My team and I were recently investigating an issue that turned out to be due to the way Enumerize behaves with database records with an invalid value. For example, we have a database table with a string column, example, with enumerized values being ['foo', 'bar', 'baz']. We had some records where example was set to baw. We then made an ActiveRecord query:

Thing.where(example: 'baw').count
#=> 70

Thing.where(example: 'baw').last
<Thing:#abc123
...
example: nil
>

This was caused by a data migration we ran on this table before adding the enumerize keyword to the model. The data migration populated records in the database with a value we didn't realize at the time was invalid. So once we added Enumerize to the model, we introduced a bug that causes the behavior to break silently.

It would be really cool if there was a configuration option that causes Enumerize to raise an error when fetching a record which has an invalid value for an enumerized attribute. It probably makes the most sense to default it to false to preserve current behavior, but I'd leave that up to the implementer.

Thanks for your consideration!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant