-
Notifications
You must be signed in to change notification settings - Fork 182
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
SQLAlchemy-Utils UUIDType TypeError: string argument without an encoding
#635
Comments
Where is the |
It's comming from SQLAlchemy-Utils
I found in the change log that this tool should be working with SQLAdmin:
Also there is such code in sqladmin/sqladmin @converts(
"sqlalchemy.dialects.postgresql.base.UUID",
"sqlalchemy.sql.sqltypes.UUID",
"sqlalchemy.sql.sqltypes.Uuid",
"sqlalchemy_utils.types.uuid.UUIDType",
)
def conv_uuid(
self, model: type, prop: ColumnProperty, kwargs: Dict[str, Any]
) -> UnboundField:
kwargs.setdefault("validators", [])
kwargs["validators"].append(validators.UUID())
return StringField(**kwargs) |
TypeError: string argument without an encoding
in helpers.py: object_identifier_valuesTypeError: string argument without an encoding
I think that this problem raised due to issue on sqlalchemy_utils package such as In helper.py file of sqladmin there is method that check wheather impl attribute of column.type or not
On using sqlalchemy_utils for uuid handling ,Here we used UUIDType where binary=False is passed
whether, we passed binary= False or binary=True , UUIDType class of (python_type attribute ) always return bytes. on this code Bytes class is called with uuid as argument ,where so that, these error occur on using with UUIDTypes. But, Is there any way to bypass these scenario from sqladmin side. |
I think you are correct in the debugging, but I think a good step is to compare https://sqlalchemy-utils.readthedocs.io/en/latest/_modules/sqlalchemy_utils/types/uuid.html#UUIDType with sqlalchemy UUID type because I don't see that one raising any issues. |
Yes, I was thinking so, impl value should be different based on binary status. I was expecting , it should be like
by changing like this, it works on my computer locally. |
Or even better it would be in |
this wasnot changed in sqlalchemy_utils currently. Once I decide to push the changes and leave it for review. But, problem is that I havenot found pydantic was used on sqlalchemy_utils . currently i leave it by creating issue on sqlqlchemy_utils. and, what do you think. How this code handle if binary = True in UUIDTypes.
I think these raise same error because for bytes data to decode , we have to call decode method of bytes class. |
Why are we returning first the So, instead of this:
Perhaps doing something like this:
|
This comment was marked as off-topic.
This comment was marked as off-topic.
I don't think that's the same problem, the error clearly is different and you are not using sqlalchemy_utils. I think you should open a different issue. |
Okay, I did it |
I've got the same problem. Have you succeeded? |
Hello, Thanks |
Checklist
master
.Describe the bug
Since I've changed
company_uuid
from str to UUID type I get following error once I want to get detailed view or edit record:SQLAlchemy model:
At first I thought that error is caused because of binary format UUID and added
UUIDType(binary=False)
but it didn't change anything also adding to main:or
PYTHONIOENCODING = 'uft-8'
to environmental variables didn't help a bit.Steps to reproduce the bug
Create model with primary key
Mapped[UUID] = mapped_column(UUIDType(binary=False), primary_key=True, index=True, default=uuid4)
Initialize database with initialdata.
Create ModelView for this table
Access http://127.0.0.1:8000/admin/{modelname}/list --> all looks ok
Try to
View
orEdit
to show detailed view or form -->TypeError: string argument without an encoding
Expected behavior
No response
Actual behavior
No response
Debugging material
Environment
OS Windows 10
Python 3.11.5
pip.txt
fastapi 0.103.1
pydantic 2.3.0
pydantic_core 2.6.3
sqladmin 0.15.0
SQLAlchemy 2.0.21
SQLAlchemy-Utils 0.41.1
uvicorn 0.23.2
WTForms 3.0.1
Additional context
No response
The text was updated successfully, but these errors were encountered: