You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi everyone,
With these versions:
Eve==0.7.10, Eve-SQLAlchemy==0.7.0, Cerberus==0.9.2, Flask-SQLAlchemy==2.3.2, SQLAlchemy==1.2.12, python 3.6.5, and postgres 9.5.5
I'm trying to insert a default value in a UUID primary key column defined as follows:
from sqlalchemy.dialects.postgresql import UUID
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
I added a custom serializer:
from eve.io.base import BaseJSONEncoder
class CustomJSONEncoder(BaseJSONEncoder):
def default(self, obj):
if isinstance(obj, UUID):
return str(obj)
elif isinstance(obj, datetime):
return obj.timestamp()
If I insert the row manually (db.session.add()) and make a GET, it works.
But when serializing the response of a POST, it fails.
The JSON serializer receives a function instead of an object.
Digging with the debugger I found that the json encoder holds this two lists:
o = SON[('id', <function uuid4 at 0x7f26fdd29158>)}
chunks = [id": "e95859ca-22dd-440f-b442-c076b8a33dc9"]
This seems incongruent.
If I go up in the callback chain until when the resource appears, I already have the id as a function, the same happens with another datetime field, while not with created_at, or updated_at (custom LAST_UPDATE).
Am I missing something regarding the validator or the schema?
As a workaround, I've tried to use server_default=sqlalchemy.text("uuid_generatev4()"), after installing the extension uuid-ossp, and it worked, but I prefer to have the generation on the language.
The text was updated successfully, but these errors were encountered:
One key aspect is that you have to generate _id yourself - uuid.uuid4().hex - and pass it as part of POST. It is not needed when you add straight to db.
Hi everyone,
With these versions:
Eve==0.7.10, Eve-SQLAlchemy==0.7.0, Cerberus==0.9.2, Flask-SQLAlchemy==2.3.2, SQLAlchemy==1.2.12, python 3.6.5, and postgres 9.5.5
I'm trying to insert a default value in a UUID primary key column defined as follows:
I added a custom serializer:
If I insert the row manually (db.session.add()) and make a GET, it works.
But when serializing the response of a POST, it fails.
The JSON serializer receives a function instead of an object.
Digging with the debugger I found that the json encoder holds this two lists:
This seems incongruent.
If I go up in the callback chain until when the resource appears, I already have the id as a function, the same happens with another datetime field, while not with created_at, or updated_at (custom LAST_UPDATE).
I also tried to add a UUID Validator as suggested here:
http://docs.python-eve.org/en/latest/tutorials/custom_idfields.html#uuid-validation
and changing the schema type from string to uuid:
Am I missing something regarding the validator or the schema?
As a workaround, I've tried to use server_default=sqlalchemy.text("uuid_generatev4()"), after installing the extension uuid-ossp, and it worked, but I prefer to have the generation on the language.
The text was updated successfully, but these errors were encountered: