running into a weird issue with sqlalchemy where I'm getting AttributeError: 'dict' object has no attribute '_sa_instance_state' and is coming from here:
schema = ApplicationSchema()
new_application = schema.load(body, session=db.session)
The model looks like this:
class ApplicationSchema(SQLAlchemyAutoSchema): # noqa
class Meta:
model = Application
include_relationships = True
load_instance = True
applicant = fields.Nested("ApplicationApplicantSchema", default=None)
legalDocs = fields.Nested("ApplicationLegalDocsSchema", default=[], many=True)
class ApplicationApplicantSchema(SQLAlchemyAutoSchema):
applicantId = fields.Int()
firstName = fields.Str()
middleName = fields.Str()
lastName = fields.Str()
birthDate = fields.Str()
ssn = fields.Str()
phoneNumber = fields.Str()
emailAddress = fields.Str()
addressLine1 = fields.Str()
addressLine2 = fields.Str()
city = fields.Str()
state = fields.Str()
zip = fields.Str()
timestamp = fields.Str()
class ApplicationLegalDocsSchema(SQLAlchemyAutoSchema):
documentId = fields.Int()
applicationId = fields.Int()
link = fields.Str()
type = fields.Str()
timestamp = fields.Str()
I have a similar model for applicants that looks the same but works:
# Create a applicant instance using the schema and the passed in applicant
schema = ApplicantSchema()
new_applicant = schema.load(applicant, session=db.session)
# Add the applicant to the database
db.session.add(new_applicant)
db.session.commit()
models for that look like this:
class ApplicantSchema(SQLAlchemyAutoSchema): # noqa
class Meta:
model = Applicant
load_instance = True
include_relationships = True
applications = fields.Nested("ApplicantApplicationSchema", default=[], many=True)
unsure why one works but the other doesn't?