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

Enum field stored as value instead of integer causing invalid enum error #59

Closed
akmalcm opened this issue Sep 23, 2024 · 5 comments
Closed

Comments

@akmalcm
Copy link
Contributor

akmalcm commented Sep 23, 2024

Currently, the enum field is being stored as its string value rather than the corresponding integer. As a result, when the enum value is changed, an error occurs:
"old_enum_value is not a valid enum_field" when calling fetch_reified_items on a snapshot.

This seems to be happening due to the enum's value changing over time, causing previously stored values to become invalid.

Example:

enum role: [admin customer] changed to enum role: [staff customer]

Error message: admin is not a valid role

@westonganger
Copy link
Owner

westonganger commented Sep 25, 2024

This is an application specific issue. Im not sure that theres anything that should be done within this library to prevent that.

You should probably adopt an enum deprecation plan similar to postgres where you can never remove an enum value from the list.

Its possible that someone could create a PR compiling a list of possible data-maintenance pitfalls if that seems useful.

@akmalcm
Copy link
Contributor Author

akmalcm commented Sep 26, 2024

Thank you for the clarification.

While I understand the suggestion regarding enum deprecation, I still feel that storing the enum's database value (the integer) rather than the Rails representation (the string) could help mitigate issues like this in the future. By using the database value in snapshots, we would avoid problems arising from changing enum strings over time.

I understand that this gem is not necessarily Rails-specific, so it may not make sense to implement something that only caters to Rails enums. However, it would be great to have an option or mechanism that allows for storing the database value (like an integer) rather than the framework-specific value (like a string in Rails). This could provide a more generic and robust solution for users across different frameworks.

@westonganger
Copy link
Owner

Ok ya I'd be open to something that solves this. Feel free to create a PR

@westonganger
Copy link
Owner

The fix for this has been merged

@westonganger
Copy link
Owner

v0.5.0 is now released which contains this fix.

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

2 participants