-
Notifications
You must be signed in to change notification settings - Fork 102
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
Improve PostgreSQL's UUID support #95
base: master
Are you sure you want to change the base?
Conversation
SQLAlchemy allows setting UUID columns to either a string representation of a UUID (e.g '46260785-9b7e-4a59-824f-af994a510673') or to a Python uuid.UUID object. Fixes dropbox#94
While this fixes your particular use case - it will break stuff for other people. Now all UUID fields on a model will be an union of I think the right solution here is to extend mypy plugin. |
I wonder if it would be possible to use an overloaded function with literal types to fix this? Maybe something like |
Interesting, I actually tried something like this and remember it didn't
work. Maybe I did something wrong.
…On Fri, Jul 26, 2019 at 1:59 PM Jukka Lehtosalo ***@***.***> wrote:
I wonder if it would be possible to use an overloaded function with
literal types to fix this? Maybe something like subprocess.Popen:
https://github.com/python/typeshed/blob/master/stdlib/3/subprocess.pyi#L809
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#95?email_source=notifications&email_token=AAHASBEHQ2GWFRDBIQKRTZ3QBLRKZA5CNFSM4IGY2EBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD24L6VQ#issuecomment-515424086>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAHASBB5ZCNZYVZALMINUYDQBLRKZANCNFSM4IGY2EBA>
.
|
I think we should try what @JukkaL proposes, using a union in this context may cause many false positives. |
It seems I took too long to reply and this line moved? Otherwise I don't see how line 809 of current master relates to this. 😕 I guess this is what you had in mind? https://github.com/python/typeshed/blob/3ad3ed82c75b4fb82f71f5500b50f18a98f12f49/stdlib/3/subprocess.pyi#L809 I just tried the following: diff --git a/sqlalchemy-stubs/dialects/postgresql/base.pyi b/sqlalchemy-stubs/dialects/postgresql/base.pyi
index d910e5c..2c6917f 100644
--- a/sqlalchemy-stubs/dialects/postgresql/base.pyi
+++ b/sqlalchemy-stubs/dialects/postgresql/base.pyi
@@ -1,8 +1,9 @@
from ... import schema
from ...engine import default, reflection
from ...sql import compiler, expression, sqltypes, type_api
-from typing import Any, Optional, Set, Type, Text, Pattern, Dict
+from typing import Any, Optional, Set, Type, Text, Pattern, Dict, overload
from datetime import timedelta
+import uuid
from sqlalchemy.types import INTEGER as INTEGER, BIGINT as BIGINT, SMALLINT as SMALLINT, VARCHAR as VARCHAR, \
CHAR as CHAR, TEXT as TEXT, FLOAT as FLOAT, NUMERIC as NUMERIC, \
@@ -66,12 +67,20 @@ class BIT(sqltypes.TypeEngine[str]):
def __init__(self, length: Optional[int] = ..., varying: bool = ...) -> None: ...
PGBit = BIT
+@overload
class UUID(sqltypes.TypeEngine[str]):
__visit_name__: str = ...
as_uuid: bool = ...
def __init__(self, as_uuid: bool = ...) -> None: ...
def bind_processor(self, dialect: Any): ...
def result_processor(self, dialect: Any, coltype: Any): ...
+@overload
+class UUID(sqltypes.TypeEngine[uuid.UUID]):
+ __visit_name__: str = ...
+ as_uuid: bool = ...
+ def __init__(self, as_uuid: bool = ...) -> None: ...
+ def bind_processor(self, dialect: Any): ...
+ def result_processor(self, dialect: Any, coltype: Any): ...
PGUuid = UUID
class TSVECTOR(sqltypes.TypeEngine[str]): However that doesn't work (same error message as #94). It seems |
You need to overload the constructor, not the class itself. |
@ilevkivskyi I made #185 to overload the constructor as per your suggestion. It seems to be pretty quiet here, it almost seems abandoned. Is it time for a community fork or is this just a temporary thing? |
Any news? |
I made a PR but it seems this repo is a bit neglected by its maintainers.
Also, with SQLAlchemy 1.4+ typing is maintained by zzzeek himself in a new
repo
…On Thu, 24 Jun 2021, 03:01 lowercase00, ***@***.***> wrote:
Any news?
I have a column uuid = db.Column(UUID(as_uuid=True), primary_key=True,
default=uuid4)
When I pass an uuid while instantiating the model I get a warning saying
that the uuid is expecting Optional[str].
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#95 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB4BSU57D4SGQSDW22RYSSDTUJ7XDANCNFSM4IGY2EBA>
.
|
|
Hi, I'm @bochecha in this ticket, but due to $circumstances I had to create a new account under my real name instead of my nickname. I'm still happy to see people interested in following on this ticket and getting a way to find its way in, but if typing is now maintained by @zzzeek upstream I'm not sure we even need this ticket anymore ? Sorry about not giving any sign of life this whole time. ($circumstances being my being hospitalized for 2 years and having to give up on all my floss activities during that time 😞) |
SQLAlchemy allows setting UUID columns to either a string representation
of a UUID (e.g '46260785-9b7e-4a59-824f-af994a510673') or to a Python
uuid.UUID object.
Fixes #94