Wrote this yesterday, didn't hit post.
More python fuckery today. Btw I'm not necessarily shitting on python in general (maybe a little bit), but it's really just this same project.
So our app is returning 500s for what should be 404s. I grab the most recent version of our dev branch, get it running and I start hitting nonexistent endpoints.
I have DEBUG set to true, I have all the logging set to DEBUG, I think.
This is still the most I'm getting in the logs:
Code:
{"request": "GET /heknowsclydecash", "user_agent": "curl/8.8.0", "event": "request_started", "level": "info"}
{"code": 500, "request": "GET /heknowsclydecash", "event": "request_finished", "level": "error"}
Some fields omitted, but you get the gist.
Even when the logging is cranked up (I guess there's maybe a trace setting I can try?), I'm still getting basically nothing useful. I even have
DEBUG_PROPAGATE_EXCEPTIONS = True
set.
When I set urlpatterns to just one handler, that one handler works. But if I request something not handled, I get 500s with the extremely unhelpful logging above.
So going on basically nothing, the most realistic culprit is that the django default 404 handler is shitting the bed, and yet somehow not logging the issue.
...
Oh! And as I write this, I just noticed something. I've been testing this with
$ curl -v http://localhost:8000/heknowsclydecash -o /dev/null
. I just got rid of the -o, and turns out, a clue! Curl's now spitting out
'HttpResponseNotFound' object has no attribute 'data'
.
At first when I saw that, I felt relief. I thought, as gay as this journey has been, at long last I have something I can grep for or google for or something.
And after trying to dig that up for like 15 more minutes or so... I have nothing. I tried a few other things. I tried custom 404 handler, custom 500 handler (no clue if I'm configuring any of these properly), I'm done with this.
Honestly, this was just a 404. Clearly a 404. Should've been a 20 minute fix with 15 of those minutes trying to remember how to get the app running (it bitches if I don't have a postgres server running and have all the env variables set).
But if this codebase is this inscrutable, fuck, my coworker has guaranteed himself magnificent job security.
The “type annotations” Python added are pretty much indefensibly dumb, IMO. To get any use out of them, you need to actually run one of the type checking libraries like mypy, and the only reliable way to remember to do that, IME, is to include linting commands that run mypy, black, etc. in your Makefile, and run those in your CI or whatever. This works fine, but if you don’t set up your repo for that early on, good luck ever doing it.
Yeah, when I discovered that the type annotations didn't do anything and I started bitching to my coworker about it, he mentioned those tools.
I've got "rig up a pre-commit type checker" somewhere on my todo list. But the thought of it is giving me flashbacks to trying to migrate a medium-sized node project to typescript.
Also the whole thing where the typing module exists, but you can do list[str] or typing.List[str] is really fucking stupid. What happened to “there should be one obvious way to do it?”
Oh lol, wonderful.
I like Python a lot, but I went from a team that did their best to define and adhere to best practices, to one that didn’t give a fuck, and that made me way more understanding of the criticisms of Python. At least the new company pays more.
Yeah, that's the thing, I've used Python on and off for years. I've always liked it better than Javascript and thought it had potential, but it's the kind of language that you really need to have discipline to keep the code quality up. Because the language itself won't offer much help.
I pick it up for a project every few years and discover new things I like, new things I hate, and a bunch of new nonsense in the community.