3👍
✅
After talking it over with a coworker we realized this actually might be desirable behavior since we would only every get one timestamp per web request. In any case, I was usually storing the return value of get_current_timestamp
and using that for any operations during that request.
To make my test pass I needed to do the following:
def test_get_current_timestamp(self):
from django.db import transaction
ts_0 = DbUtils.get_current_timestamp()
transaction.commit_unless_managed()
time.sleep(1)
ts_1 = DbUtils.get_current_timestamp()
transaction.commit_unless_managed()
delta_seconds = (ts_1 - ts_0).seconds
assert 1 <= delta_seconds <= 3
As @a_horse_with_no_name notes: CURRENT_TIMESTAMP is the time at the beginning of the transaction.
Source:stackexchange.com