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
I would ideally like to be able to add the following dictionary to the database, without adding a new task to the ToDoTask table if it already exists (hence the unique=True constraint on the model).
When trying to use the Marshmallow .load() method, I run into the error that the data cannot be added due to the unique constraint because dictionary already includes that value. I would like to only add the corresponding foreign key to the to ToDo table instead.
I am getting an integrity error here because of the unique constraint on the ToDoTask.task column although I want Marshmallow to recognize the value already exists and only fetch it's ID and enter it in the ToDo table under task_id.
If the ToDoTask table contains 1 row with task equal to "Gym", I would like to populate the User table with the email="[email protected]", password="test" and then the ToDo table with user_id=2, task_id=1
load_instance only queries for existing objects using the primary key. Even if you overloaded ToDoTaskSchema.get_instance() to query on the name, the schema doesn't appear to handle copying the nested task.id to task_id, so you would probably have to add a @post_load hook to ToDoSchema to test for this situation and copy it.
I suspect this behavior would be generally useful:
Try querying unique fields when the primary key is not provided
Propagate nested primary keys to foreign keys when instances are found
I have the following SQLAlchemy Models:
I went ahead and created the corresponding Marshmallow schemas:
I would ideally like to be able to add the following dictionary to the database, without adding a new task to the
ToDoTask
table if it already exists (hence theunique=True
constraint on the model).When trying to use the Marshmallow
.load()
method, I run into the error that the data cannot be added due to the unique constraint because dictionary already includes that value. I would like to only add the corresponding foreign key to the to ToDo table instead.Given the following code:
I am getting an integrity error here because of the unique constraint on the ToDoTask.task column although I want Marshmallow to recognize the value already exists and only fetch it's ID and enter it in the ToDo table under task_id.
If the
ToDoTask
table contains 1 row with task equal to "Gym", I would like to populate theUser
table with theemail="[email protected]"
,password="test"
and then theToDo
table withuser_id=2
,task_id=1
Here is the link on SO if anyone is interested: https://stackoverflow.com/questions/73335484/how-to-deserialize-a-multiple-nested-dictionary-using-marshmallow-while-abiding
The text was updated successfully, but these errors were encountered: