kolofordjango / kolo

See everything happening in your running Django app. All without leaving VSCode
https://kolo.app
486 stars 14 forks source link

impossibly old requests #37

Closed caleb15 closed 11 months ago

caleb15 commented 1 year ago

I was clicking through "older requests" and I started seeing requests from 6 years ago. I mean, yeah, I wanted to see older requests, but not that old :joy:

image

caleb15 commented 1 year ago

Ah - maybe kolo ran when I ran our unit/integration tests, some of which set custom times and do API calls? :thinking: :thinking:

I'm also seeing a bunch of requests I don't remember making.

wilhelmklopp commented 1 year ago

haha! I've also seen super old/incorrect timestamps when using kolo in tests that change/freeze time.

Any change you ran the tests with kolo run or still have some with kolo.enabled() blocks set?

caleb15 commented 1 year ago

Any change you ran the tests with kolo run or still have some with kolo.enabled() blocks set?

I double-checked: no kolo run and I don't have any kolo in my code.... besides the middleware, that is. Does just putting it in the middleware activate it when running tests?

I checked and I'm able to reproduce the problem. I deleted the Kolo DB to get a fresh slate and then ran tests with python manage.py test --keepdb --tag=mytaghere. We use the builtin unittest framework. After I ran the tests a bunch of very old requests appeared in Kolo.

LilyFoote commented 1 year ago

Does just putting it in the middleware activate it when running tests?

Yes. Specifically, Kolo will trace any request that goes through middleware, usually those generated by the Django test client. There's a few things that will disable the middleware:

wilhelmklopp commented 1 year ago

Worth mentioning also that DEBUG=False is set by default when using python manage.py test (Debug can be set to True using python manage.py test --debug-mode)

@caleb15 just a guess, but maybe some tests in your codebase are setting DEBUG=True?

caleb15 commented 1 year ago

Talked about this on a call, turns out certain tests are setting DEBUG to true, causing kolo to run. That explains that!

It would still be nice if requests were labeled with the actual time instead of the mock time, but not sure if that's even possible. Maybe if you make directly make a system call? See https://adamj.eu/tech/2020/06/03/introducing-time-machine/ (we use the time machine library)

Or you could have a seperate process just for returning the correct time :thinking: