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

DateTimeField with auto_now_add=True option can not be updated with value #96

Open
M1ha-Shvn opened this issue Jan 11, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@M1ha-Shvn
Copy link
Owner

Example

class MyModel:
  dt = DateTimeField(auto_now_add=True)
  
obj = MyModel.objects.create()

MyModel.objects.pg_bulk_update({1: {"dt": datetime(2024, 1, 1, tzinfo=pytz.utc}})

obj.refresh_from_db()
print(obj.dt)

I expect date to be updated here, but it is not updated due to the usage of NowSetFunction(if_null=False). It ignores provided value, and as a result of COALESCE function leaves value unchanged.

@M1ha-Shvn M1ha-Shvn added the bug Something isn't working label Jan 11, 2024
@M1ha-Shvn M1ha-Shvn changed the title DateField with auto_now_add=True option can not be updated with value DateTimeField with auto_now_add=True option can not be updated with value Jan 11, 2024
@M1ha-Shvn
Copy link
Owner Author

Temporary fix: use set_functions={"dt": "eq"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant