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

Fixed type tg_id field in Client class #22

Merged
merged 4 commits into from
Oct 14, 2024
Merged

Conversation

anmv
Copy link
Contributor

@anmv anmv commented Sep 26, 2024

Fixed type tg_id field in Client class #21

@@ -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
Copy link
Owner

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].

Copy link
Contributor Author

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 ?

Copy link
Contributor Author

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

Copy link
Owner

@iwatkot iwatkot Sep 26, 2024

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Goosegit11

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.

@@ -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
Copy link
Owner

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

Copy link
Contributor Author

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"

@@ -1,5 +1,7 @@
"""This module contains the Client class which represents a client in the XUI API."""

from typing import Optional
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove import

@iwatkot
Copy link
Owner

iwatkot commented Oct 10, 2024

@anmv, hello again!

I'm back, so my question would be:
If we set the default value to None, will it crash on the API side?
If yes, let's just leave something like
int | str | None with default value=""

What are your thoughts about it?

Thank you
Sincerely

@iwatkot iwatkot linked an issue Oct 10, 2024 that may be closed by this pull request
@anmv
Copy link
Contributor Author

anmv commented Oct 13, 2024

@iwatkot i don't know about None as default value. I don't have error, when default value was error

@anmv
Copy link
Contributor Author

anmv commented Oct 13, 2024

int | str | None with default value=""

ok, done

@@ -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.
"""

""""""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove it, please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iwatkot wow, interesting :-D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove it, please

done

@iwatkot
Copy link
Owner

iwatkot commented Oct 13, 2024

@anmv remove the extra quotes and I'm merging it.

@iwatkot iwatkot merged commit fe32811 into iwatkot:main Oct 14, 2024
1 of 2 checks passed
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.

error field type in Client object
3 participants