-
Notifications
You must be signed in to change notification settings - Fork 94
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
'list' object has no attribute '_sa_adapter'
#346
Comments
This is a lot to chew on, so I thought I'd give a simpler explanation since I've had time to think through this.
persist this works. But when I'm trying to create a new record, i.e...
I get this error about an |
@zeke8402 I have been using this pattern for quite some time and havent found any issues. Note - i dont use partial=True, ib my case we create it from scratch |
Perhaps it does relate, as I have a pivot table for the many-to-many relation
Again marshmallow-sqlalchemy has no issues updating this relationship, it's only when creating a new product does this happen. |
Hey everyone!
I'm trying to persist a schema that has a one-to-many relationship. For example, I am persisting a 'product' that can have many 'categories'
I have defined the Schemas like so
Editing an item seems to work totally fine. (context: request_data is simply a dict with all required fields from the schema)
Running the above code when changing how many categories are associated with the product works flawlessly. But when I try to create an object...
It returns the following error:
'list' object has no attribute '_sa_adapter'
Further investigation revealed that when loading an existing instance, the categories are inside of an
InstrumentedList
, whereas attempting to create a product with many, existing categories, creates a regular List, instead. I think that is why this error message is happening, but I'm not sure why loading a new, transient object would result in a different list type for the categories. Perhaps it is because marshmallow-sqlalchemy is anticipating that these are new categories that I would want to persist? But I haven't found anything in the documentation supporting that theory.I've attempted to modify the
ProductSchema
as well, and change thecategories
tocategories = ma.Nested(CategorySchema, many=True)
, and I've also triedcategories = fields.Related(CategorySchema)
, to no avail. Any help would be greatly appreciated!The text was updated successfully, but these errors were encountered: