News for hackers. Stuff that matters.
Re:A ChatGPT mistake cost us $10k by randomdata on Monday June 10, 2024 @08:56AM (#40633099)
> it's collocating the idea of setup and cleanup together.

Okay, sure, but Rollback is the cleanup function. You always want to rollback – you only sometimes want to commit. I suppose this confirms that someone got their logic mixed up.

Re:A ChatGPT mistake cost us $10k by owl57 on Tuesday June 11, 2024 @02:43AM (#40643263)
> You always want to rollback

This phrase highlights the confusion. If you learned SQL before Go, you want to rollback only on error.

Every time I write `defer tx.Rollback()`, I cringe and have to remind myself that yes, it's actually ok to call a method called `Rollback` after succesfully writing data.

Re:A ChatGPT mistake cost us $10k by randomdata on Tuesday June 11, 2024 @09:35AM (#40646023)
If you learned SQL before Go, you'd know the pattern works just fine and is arguably a good sanity check.

    BEGIN;
    INSERT INTO ...
    COMMIT;
    ROLLBACK;
It is not some kind of Go-ism. The Go database/sql package actually executes ROLLBACK in the SQL engine. Check out the error returned by it.

Perhaps you mean learned SQL in the context of languages that consider a failed rollback an exception? In that case one needs to be careful to not rollback, else be stricken to handling the exception, which programmers seem to hate doing.

Re:A ChatGPT mistake cost us $10k by owl57 on Tuesday June 11, 2024 @11:53AM (#40647798)
> The Go database/sql package actually executes ROLLBACK in the SQL engine.

No: https://github.com/golang/go/blob/beaf7f3282c2548267d3c89441...

Re:A ChatGPT mistake cost us $10k by randomdata on Tuesday June 11, 2024 @12:14PM (#40648064)
Fair enough, although it wouldn't matter if it did. Nothing would change other than some unnecessary computation would occur. SQL supports it just fine. Anyone who learned SQL first would know that quite well.
Re:A ChatGPT mistake cost us $10k by owl57 on Tuesday June 11, 2024 @01:17PM (#40648932)
Fair as well. It's just sending a command which you know will fail, and even relying on the fact it fails, feels wrong, whether it sends a request over network or not.

BTW I checked and it's not an error in Postgres, only a warning. Still not something I would want in my database logs for the happy path.

Re:A ChatGPT mistake cost us $10k by randomdata on Tuesday June 11, 2024 @01:42PM (#40649252)
You know it will fail if you didn't screw up anything else.

But it's a good sanity check/safety measure to call it anyway incase you made a mistake elsewhere. An errant rollback is more likely to be caught in testing than a dangling transaction.