sqlalchemy attribute is tuple after assignment
Question:
I’m using SQLAlchemy 1.0.12. When I have an instance of my model & assign a new value to an attribute, I get a tuple
instead of the value.
type(self.address1)
<class 'tuple'>
This wreaks a bit of havoc when I try to use marshmallow-sqlalchemy
0.8.1 to do a dump
:
SomeSchema().dump(self).data
The assigned basically doesn’t show up in the dumped data because it doesn’t know how to marshal a tuple
. The only way to “flatten” the tuple/attributes is to do a session.commit()
before doing a dump()
.
Is there a cleaner way? I have other instances to change/create before I want to do a session.commit()
.
Answers:
It was a user error. I accidentally had a comma at the end of an assignment, and python created a tuple as the return value.
This returns an integer
1
This returns a tuple
1,
Removing the comma in my return
statement as suggested in the comments by Ilja worked
I’m using SQLAlchemy 1.0.12. When I have an instance of my model & assign a new value to an attribute, I get a tuple
instead of the value.
type(self.address1)
<class 'tuple'>
This wreaks a bit of havoc when I try to use marshmallow-sqlalchemy
0.8.1 to do a dump
:
SomeSchema().dump(self).data
The assigned basically doesn’t show up in the dumped data because it doesn’t know how to marshal a tuple
. The only way to “flatten” the tuple/attributes is to do a session.commit()
before doing a dump()
.
Is there a cleaner way? I have other instances to change/create before I want to do a session.commit()
.
It was a user error. I accidentally had a comma at the end of an assignment, and python created a tuple as the return value.
This returns an integer
1
This returns a tuple
1,
Removing the comma in my return
statement as suggested in the comments by Ilja worked