-
Notifications
You must be signed in to change notification settings - Fork 269
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
ignore
doesn't seem to work in more complicated setup (Django + S3 / boto)
#331
Comments
How deep is the call stack? Freezegun only looks 5 levels deep by default. You can change this with call_stack_inspection_limit |
It's pretty deep from what I've observed, around 35 levels. I've set For reference, I'm posting the call stack here:
|
I can confirm the issue, Botocore calls
That's at least my understanding of the problem. Did you find a solution @radoh ? |
So for the people you might run into the issue: It works if you change the
However, this really hacky and I suppose that there is a bug somewhere in |
I believe we've run into a similar issue with urllib3/urllib3@3f21165#diff-542c95910a277028550d2c8943e8c49bbcb10f9af96e35d0a0eee99b8cfe9e8c Since then our tests have been printing SystemTimeWarnings and adding both |
Also ran into this issue, specifically getting
when writing tests that also happen to use s3 based storage. Adding the related packages to the ignore list doesn't seem to have any effect. |
@MythicManiac you noticed #391 and #430? |
Ah, I didn't, but good to know 👍 just worked around it a bit differently in our case. |
Any update on this issue? It would be nice to know why |
The cause of the bug: freezgun unconditionally patches The ignore mechanism is only working on the part which traverses import modules and patches functions and classes which were already imported from datetime module, e.g. botocore uses datetime like this: One solution to this is to check stack at every call of fake datetime as proposed earlier, but is computationally more expensive (I'm not sure how this affects use cases, maybe this can be an option alongside ignore list) |
You probably want to migrate to time-machine. It is well maintained and by its different design does not have this issue. |
I didn't find any ignore facilities in neither time-machine nor libfaketime |
I am using Django with S3 as the file storage (which uses boto3/botocore libs). I have a "management" command which creates some Django instances - I use freezegun, so these instances appear to be created in the past. However some of these models contain files, that are being saved to S3 - which raises some exceptions:
this is due to some authentication code in
botocore.auth
module, that checks for time differences. I tried to solve this issue usingignore
parameter (freeze_time(datetime_in_past, ignore=['botocore'])
), but it didn't help,botocore.auth
still used theFakeDatetime
(I used debugger with breakpoints to pinpoint the issue).I tried to recreate the issue with a simple reproducible example, so I came up with following:
This code correctly works, freeze_time ignore
test_time
and it printsreal datetime.now: <real time>
. However if I omit the marked unused import intest.py
, it doesn't work - freeze_time doesn'tignore
the module and the script prints outreal datetime.now: <fake time>
.I thought I could try out something similar in my real Django go, so I did following:
This hasn't worked no matter what I imported or ignored,
botocore.auth
still continued to useFakeDatetime
...Is there a bug in freeze_time? Or am I misusing the library in some way? Why does it behave like this?
The text was updated successfully, but these errors were encountered: