Skip to content
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

Error `TypeError: unhashable type: 'list'` #223

Closed
heckad opened this issue Jul 3, 2019 · 3 comments · Fixed by #242

Comments

@heckad
Copy link
Contributor

commented Jul 3, 2019

If to try to deserialize model which should have relationship one to many and put the array in this field then there will be an error TypeError: unhashable type: 'list' instead of ValidationError
Example

class M(Base):
   ....
   store_id = Column(ForeignKey('stores.id'))
   store = relationship("Store", uselist=False)
   ....

M().load({"store":[1,2,3]})
@sloria

This comment has been minimized.

Copy link
Member

commented Aug 31, 2019

It's hard to diagnose this without the schema definition. Can you make a minimal repro case?

@heckad

This comment has been minimized.

Copy link
Contributor Author

commented Aug 31, 2019

from marshmallow_sqlalchemy import ModelSchema
from sqlalchemy import Column, Integer, ForeignKey, create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, sessionmaker

Base = declarative_base()


class M(Base):
    __tablename__ = 'ms'
    id = Column(Integer, primary_key=True)
    tore_id = Column(ForeignKey('stores.id'))
    store = relationship("Store", uselist=False)


class Store(Base):
    __tablename__ = 'stores'
    id = Column(Integer, primary_key=True)


class MSchema(ModelSchema):
    class Meta:
        model = M


engine = create_engine('sqlite:///:memory:')
Base.metadata.create_all(bind=engine)

if __name__ == '__main__':
    session = sessionmaker(bind=engine)()
    session.add(Store(id=1))
    session.commit()
    MSchema().load({"store": [1, 2, 3]}, session)

@sloria

This comment has been minimized.

Copy link
Member

commented Sep 1, 2019

Thanks for the repro. I'll work on a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.