top | item 40628032

(no title)

Lunrtick | 1 year ago

They could also have done default=uuid.uuid4 to have a new id each time, or default=lambda : str(uuid.uuid4()). It's not really related to whether or not it's a database default.

It seems quite unfair to place the blame on SQLAlchemy here, or even Python.

Even a statically typed language wouldn't prevent this kind of issue - the author of the code is the only person who can decide when they mean "use this exact string each time" or "use this function to give me a new string each time".

I suppose a column description API could follow the dataclass style definition, with different argument names for default and default_func. That would (I think) prevent this from happening.

discuss

order

jowea|1 year ago

I could imagine some sort of static analysis saying that using a constant value instead of a function is a mistake for columns with unique set.

Lunrtick|1 year ago

That's a good point! I suppose in Python that could be a guard in the column definition function.

throw156754228|1 year ago

Exactly, this is an error that should've been picked up statically, before unit even.