Skip to content

Commit

Permalink
fix 332: to address column typo asper doc
Browse files Browse the repository at this point in the history
  • Loading branch information
indiVar0508 committed Sep 5, 2022
1 parent 4f80ff6 commit b609539
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ Contributors
- Bruce Adams `@bruceadams <https://github.com/bruceadams>`_
- Justin Crown `@mrname <https://github.com/mrname>`_
- Jeppe Fihl-Pearson `@Tenzer <https://github.com/Tenzer>`_
- Indivar `@indiVar0508 <https://github.com/indiVar0508>`_
12 changes: 10 additions & 2 deletions src/marshmallow_sqlalchemy/fields.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from marshmallow import fields
from marshmallow.utils import is_iterable_but_not_string

Expand Down Expand Up @@ -41,9 +42,16 @@ class Related(fields.Field):
"expected a dictionary with keys {keys!r}"
}

def __init__(self, column=None, **kwargs):
def __init__(self, columns=None, column=None, **kwargs):
if column is not None:
warnings.warn(
"`column` parameter is deprecated and will be removed in future releases. "
"Use `columns` instead.",
DeprecationWarning,
)
columns = column
super().__init__(**kwargs)
self.columns = ensure_list(column or [])
self.columns = ensure_list(columns or [])

@property
def model(self):
Expand Down
8 changes: 8 additions & 0 deletions tests/test_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,14 @@ def test_field_for(self, models, session):
field = field_for(models.Student, "full_name", field_class=fields.Date)
assert type(field) == fields.Date

def test_related_initialization_warning(self, models, session):
with pytest.warns(DeprecationWarning) as record:
Related(column=[])
assert (
record[0].message.args[0]
== "`column` parameter is deprecated and will be removed in future releases. Use `columns` instead."
)

def test_field_for_can_override_validators(self, models, session):
field = field_for(
models.Student, "full_name", validate=[validate.Length(max=20)]
Expand Down

0 comments on commit b609539

Please sign in to comment.