-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Fixed type tg_id field in Client class #22
Conversation
py3xui/client/client.py
Outdated
@@ -65,5 +67,5 @@ class Client(BaseModel): | |||
flow: str = "" | |||
limit_ip: int = Field(default=0, alias=ClientFields.LIMIT_IP) # type: ignore | |||
sub_id: str = Field(default="", alias=ClientFields.SUB_ID) # type: ignore | |||
tg_id: str = Field(default="", alias=ClientFields.TG_ID) # type: ignore | |||
tg_id: Optional[int] = Field(default="", alias=ClientFields.TG_ID) # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default value is incompatible with the typing.
String can not be assigned as default value for Optional[int].
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iwatkot wow, really) default=None is ok ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
panel 3x-ui return None if empty value in tg_id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anmv please test that call to the API with default value None will not raise an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1
tg_id: Optional[str] = Field(default=None, alias=ClientFields.TG_ID)
validation error for UiInbound
settings.clients.4.tgId
Input should be a valid string [type=string_type, input_value=511122566, input_type=int]
For further information visit https://errors.pydantic.dev/2.9/v/string_type
2
tg_id: Optional[int] = Field(default=None, alias=ClientFields.TG_ID)
validation error for UiInbound
settings.clients.0.tgId
Input should be a valid integer, unable to parse string as an integer [type=int_parsing, input_value='', input_type=str]
For further information visit https://errors.pydantic.dev/2.9/v/int_parsing
default panel return str type
3
tg_id: Optional[int | str] = Field(default=None, alias=ClientFields.TG_ID)
Worked perfect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or default = "", i think this worked too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File "/root/py-scripts/lib/python3.10/site-packages/py3xui/client/client.py",
line 69, in Client
tg_id: Optional[int | str] = Field(default=None, alias=ClientFields.TG_ID)
NameError: name 'Optional' is not defined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NameError: name 'Optional' is not defined
This is weird, I can clearly see the import of the Optional from typing.
But still, we'll change it to modern type hints.
py3xui/client/client.py
Outdated
@@ -65,5 +67,5 @@ class Client(BaseModel): | |||
flow: str = "" | |||
limit_ip: int = Field(default=0, alias=ClientFields.LIMIT_IP) # type: ignore | |||
sub_id: str = Field(default="", alias=ClientFields.SUB_ID) # type: ignore | |||
tg_id: str = Field(default="", alias=ClientFields.TG_ID) # type: ignore | |||
tg_id: Optional[int | str] = Field(default=None, alias=ClientFields.TG_ID) # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to modern typehint int | str | None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int | str | None
Ok, but api dont return "None"
py3xui/client/client.py
Outdated
@@ -1,5 +1,7 @@ | |||
"""This module contains the Client class which represents a client in the XUI API.""" | |||
|
|||
from typing import Optional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove import
@anmv, hello again! I'm back, so my question would be: What are your thoughts about it? Thank you |
@iwatkot i don't know about None as default value. I don't have error, when default value was error |
ok, done |
py3xui/client/client.py
Outdated
@@ -47,7 +47,7 @@ class Client(BaseModel): | |||
tg_id (str): The Telegram ID of the client. Optional. | |||
total_gb (int): The total amount of data transferred by the client in GB. Optional. | |||
""" | |||
|
|||
"""""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove it, please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iwatkot wow, interesting :-D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove it, please
done
@anmv remove the extra quotes and I'm merging it. |
Fixed type tg_id field in Client class #21