Repository: marshmallow-code/marshmallow-sqlalchemy

Issue:
Error `TypeError: unhashable type: 'list'`
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]})


Discussion:

Patch:
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 9f9ec19..904263a 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -1,6 +1,14 @@
 Changelog
 ---------
 
+0.17.2 (unreleased)
++++++++++++++++++++
+
+Bug fixes:
+
+* Fix error handling when passing an invalid type to ``Related`` (:issue:`223`).
+  Thanks :user:`heckad` for reporting.
+
 0.17.1 (2019-08-31)
 +++++++++++++++++++
 
diff --git a/src/marshmallow_sqlalchemy/fields.py b/src/marshmallow_sqlalchemy/fields.py
index 64d19ac..10a477c 100644
--- a/src/marshmallow_sqlalchemy/fields.py
+++ b/src/marshmallow_sqlalchemy/fields.py
@@ -127,7 +127,15 @@ class Related(fields.Field):
             ).one()
         else:
             # Use a faster path if the related key is the primary key.
-            result = query.get([value.get(prop.key) for prop in self.related_keys])
+            lookup_values = [value.get(prop.key) for prop in self.related_keys]
+            try:
+                result = query.get(lookup_values)
+            except TypeError:
+                keys = [prop.key for prop in self.related_keys]
+                if hasattr(self, "make_error"):
+                    raise self.make_error("invalid", value=value, keys=keys)
+                else:  # marshmallow 2
+                    self.fail("invalid", value=value, keys=keys)
             if result is None:
                 raise NoResultFound
         return result


Test patch:
diff --git a/tests/test_marshmallow_sqlalchemy.py b/tests/test_marshmallow_sqlalchemy.py
index cc77550..26e6bf3 100644
--- a/tests/test_marshmallow_sqlalchemy.py
+++ b/tests/test_marshmallow_sqlalchemy.py
@@ -758,6 +758,17 @@ class TestModelSchema:
         assert load_data is student
         assert load_data.current_school == student.current_school
 
+    def test_model_schema_loading_invalid_related_type(
+        self, models, schemas, student, session
+    ):
+        schema = schemas.StudentSchema()
+        dump_data = unpack(schema.dump(student))
+        dump_data["current_school"] = [1]
+        with pytest.raises(
+            ValidationError, match="Could not deserialize related value"
+        ):
+            schema.load(dump_data)
+
     def test_model_schema_loading_missing_field(
         self, models, schemas, student, session
     ):