-
Notifications
You must be signed in to change notification settings - Fork 8
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
Preventing data mutation in format_fields #75
Comments
@mamico I noticed a similar problem when getting #37 up-to-date . In this PR which reworks the API with fields to be a dedicated field object, I avoid the problem by re-getting the fields every time Originally I wanted to compute all the fields once at the start after validation so as to only have to do this work once, however it looks like the |
@JeffersonBledsoe Do you see any contraindications to using |
@mamico I agree that it's counter-intuitive. I mentioned my other PR because it should already solve this problem by assigning all of the values in the passed in |
def format_fields(self, fields):
The fields object passed as an argument is modified within the function, which can lead to issues if the function is called multiple times, as it may result in broken or unintended data.
For example, in the following snippet:
It seems get_localized_time expects a datetime object or an ISO-formatted string, not a localized string.
A quick fix to avoid mutating the original fields object is to add a deepcopy at the start of the function:
@JeffersonBledsoe thoughts ?
see #34
The text was updated successfully, but these errors were encountered: