From f19b8e2184eb3d38860b6940a6046ffb01c95579 Mon Sep 17 00:00:00 2001 From: Steven Loria Date: Tue, 30 Jan 2024 13:03:09 -0500 Subject: [PATCH] Remove support for info={'marshmallow': ...} (#567) --- CHANGELOG.rst | 4 +++- src/marshmallow_sqlalchemy/convert.py | 15 --------------- tests/conftest.py | 8 ++++---- tests/test_conversion.py | 18 ------------------ 4 files changed, 7 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index fe64338..96c45ff 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,7 +5,9 @@ Changelog +++++++++++++++++++ * Support marshmallow>=3.10.0. -* Remove ``packaging`` as a requirement. +* Passing `info={"marshmallow": ...}` to SQLAlchemy columns is removed, as it is redundant with + the ``auto_field`` functionality. +* Remove ``packaging`` as a dependency. * Support Python 3.12. 0.30.0 (2024-01-07) diff --git a/src/marshmallow_sqlalchemy/convert.py b/src/marshmallow_sqlalchemy/convert.py index 86377b5..5be23f2 100644 --- a/src/marshmallow_sqlalchemy/convert.py +++ b/src/marshmallow_sqlalchemy/convert.py @@ -1,7 +1,6 @@ import functools import inspect import uuid -import warnings import marshmallow as ma import sqlalchemy as sa @@ -284,20 +283,6 @@ def _get_field_kwargs_for_property(self, prop): self._add_relationship_kwargs(kwargs, prop) if getattr(prop, "doc", None): # Useful for documentation generation kwargs["metadata"]["description"] = prop.doc - info = getattr(prop, "info", dict()) - overrides = info.get("marshmallow") - if overrides is not None: - warnings.warn( - 'Passing `info={"marshmallow": ...}` is deprecated. ' - "Use `SQLAlchemySchema` and `auto_field` instead.", - DeprecationWarning, - stacklevel=2, - ) - validate = overrides.pop("validate", []) - kwargs["validate"] = self._merge_validators( - kwargs["validate"], validate - ) # Ensure we do not override the generated validators. - kwargs.update(overrides) # Override other kwargs. return kwargs def _add_column_kwargs(self, kwargs, column): diff --git a/tests/conftest.py b/tests/conftest.py index d408607..1a790d8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -107,11 +107,11 @@ class Student(Base): ) # Test complex column property - subquery = sa.select(sa.func.count(student_course.c.course_id)).where( - student_course.c.student_id == id + course_count = column_property( + sa.select(sa.func.count(student_course.c.course_id)) + .where(student_course.c.student_id == id) + .scalar_subquery() ) - subquery = subquery.scalar_subquery() - course_count = column_property(subquery) @property def url(self): diff --git a/tests/test_conversion.py b/tests/test_conversion.py index 0ad7514..1499e2e 100644 --- a/tests/test_conversion.py +++ b/tests/test_conversion.py @@ -98,24 +98,6 @@ def test_overridden_with_fk(self, models): graded_paper_fields = fields_for_model(models.GradedPaper, include_fk=False) assert "id" in graded_paper_fields - def test_info_overrides(self, models): - class TestModel(models.Course): - test = sa.Column( - sa.Text, - nullable=True, - info=dict( - marshmallow=dict( - validate=[validate.Length(max=1000)], required=True - ) - ), - ) - - fields_ = fields_for_model(TestModel) - field = fields_["test"] - validator = contains_validator(field, validate.Length) - assert validator.max == 1000 - assert field.required - def test_rename_key(self, models): class RenameConverter(ModelConverter): def _get_field_name(self, prop):