News for hackers. Stuff that matters.
Re:A ChatGPT mistake cost us $10k by SmellTheGlove on Sunday June 09, 2024 @06:16PM (#40628078)
This is a pretty common mistake with sqlalchemy whether you’re using ChatGPT or not. I learned the same lesson years ago, although I caught it while testing. I write plenty of python and I just don’t often pass functions in as parameters. In this case you need to!

For something like this where you’re generating a unique id and probably need it in every model, it’s better to write a new Base model that includes things like your unique id, created/changed at timestamps, etc. and then subclass it for every model. Basically, write your model boilerplate once and inherit it. This way you can only fuck this up once and you’re bound to catch it early before you make this mistake in a later addition like subscription management.

Re:A ChatGPT mistake cost us $10k by hamasho on Sunday June 09, 2024 @07:47PM (#40628579)
I wonder are there linters to detect those types of mistakes for SQLAlchemy. Even though I'm aware of such pitfalls, it's nice if linters can catch them cause I'm not confident to cache them all the time during code review.

Some linters like pyright can identify dangerous defaults in function call, like `def hello(x=[]): pass` (mutable values shouldn't be a default). Linter plugins for widely-used and critical libraries like SQLAlchemy are nice to have.

Re:A ChatGPT mistake cost us $10k by whakim on Sunday June 09, 2024 @09:32PM (#40629249)
The mutable-default-arguments issue is easy for a third-party to linter to catch because it doesn't require any specific knowledge about primary keys and databases. Are there static typing plugins for other common packages that would catch issues like this?
Re:A ChatGPT mistake cost us $10k by aragilar on Sunday June 09, 2024 @10:42PM (#40629628)
I personally use pylint, which I've found to be the most aggressive python linter.
Re:A ChatGPT mistake cost us $10k by wateroutflow on Sunday June 09, 2024 @06:18PM (#40628086)
Yea, more of an issue of how this python library can cause misunderstandings, and ChatGPT failing in the same misunderstanding that would have been made by an engineer who lacks experience in that library.

This mistake would have happened even if they did not use ChatGPT.

Re:A ChatGPT mistake cost us $10k by spamizbad on Sunday June 09, 2024 @09:25PM (#40629197)
Ah, but it’s not a characteristic of SQLAlchemy tho. It’s how Python evaluates statements. Both Peewee and the Django ORM work on the same principle with default values.

The intent is to pass a callable, not to call a function and populate an argument with what it returns.

Re:A ChatGPT mistake cost us $10k by SmellTheGlove on Sunday June 09, 2024 @10:31PM (#40629569)
Correct, it's not specific to sqlalchemy - I'm just saying I notice this a lot with sqlalchemy. Probably because it was the first significant bug I had to figure out how to fix when I introduced it in one of my first apps. I guess we never forget the first time we shot ourselves in the foot.
Re:A ChatGPT mistake cost us $10k by hehdhdjehehegwv on Sunday June 09, 2024 @09:25PM (#40629198)
Depending on your viewpoint, ORM are by nature a mistake.

The time people spend learning the quirks of an ORM is much better put into learning SQL.

Re:A ChatGPT mistake cost us $10k by thruway516 on Sunday June 09, 2024 @09:41PM (#40629311)
Honestly same can be said about a lot of frameworks. You will pry my vanilla JS debugged with print statements hand-coded in vi from these hands only when they're cold and dead.
Re:A ChatGPT mistake cost us $10k by hehdhdjehehegwv on Monday June 10, 2024 @02:28AM (#40630790)
Yeah, I have a workflow where I inject JavaScript into arbitrary webpages and store the results. There’s no substitute for vanilla js knowledge when you’re in the weeds.
Re:A ChatGPT mistake cost us $10k by thruway516 on Sunday June 09, 2024 @09:31PM (#40629241)
That explains where ChatGpt is getting that from. I guess it is only as smart as the average coder.