Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't use typing with ServerDefaultType #180

Merged
merged 1 commit into from Sep 29, 2021
Merged

Conversation

zzzeek
Copy link
Member

@zzzeek zzzeek commented Sep 29, 2021

The server default is any expression that is passed as DDL
to the database and these usually don't have SQL types explicitly
stated.

With the code as is, pylance is complaining about this:

Column(DateTime(), server_default=func.now())

and requiring I do this:

Column(DateTime(), server_default=func.now(type_=DateTime))

people don't need to do that, server_defaults SQL type always comes
from the column type and doesn't normally need to be stated.

Also, column_server_default.py was importing "functions as func",
which is wrong. "func" is not a module it's a namespace object,
fixed that.

@CaselIT
Copy link
Member

CaselIT commented Sep 29, 2021

I think you need to update the tests

@zzzeek
Copy link
Member Author

zzzeek commented Sep 29, 2021

i looked, wasnt sure

@zzzeek
Copy link
Member Author

zzzeek commented Sep 29, 2021

oh its this:

# EXPECTED_MYPY: Cannot infer type argument 1 of "Column"
d = Column(Boolean, server_default=func.now(), nullable=False)

yeah, i dunno, that's a weird mistake not very real world. like if server_default does have a type, then sure, but literally pylance is not working with the actual func.now() because I guess we dont have that in the stubs. so i think ill remove that case.

The server default is any expression that is passed as DDL
to the database and these usually don't have SQL types explicitly
stated.

With the code as is, pylance is complaining about this:

    Column(DateTime(), server_default=func.now())

and requiring I do this:

    Column(DateTime(), server_default=func.now(type_=DateTime))

people don't need to do that, server_defaults SQL type always comes
from the column type and doesn't normally need to be stated.

Also, column_server_default.py was importing "functions as func",
which is wrong. "func" is not a module it's a namespace object,
fixed that.
@zzzeek
Copy link
Member Author

zzzeek commented Sep 29, 2021

yeah that test case was only working because func was pointing to the functions module, which is also not how it's done

@zzzeek zzzeek merged commit b426ac8 into master Sep 29, 2021
@zzzeek zzzeek deleted the server_default_no_type branch September 29, 2021 15:24
@CaselIT
Copy link
Member

CaselIT commented Sep 29, 2021

if you like you can publish

@zzzeek
Copy link
Member Author

zzzeek commented Sep 29, 2021

ooh w the button ???

@CaselIT
Copy link
Member

CaselIT commented Sep 29, 2021

Yep

@zzzeek
Copy link
Member Author

zzzeek commented Sep 29, 2021

stimpy-red

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants