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 7, 2022
1 parent 4f80ff6 commit 87e7ef8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
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
16 changes: 16 additions & 0 deletions tests/test_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,22 @@ 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,
match="column` parameter is deprecated and will be removed in future releases. Use `columns` instead.",
):
Related(column=[])

def test_related_initialization_with_columns(self, models, session):
ret = Related(columns=["TestCol"])
assert len(ret.columns) == 1
assert ret.columns[0] == "TestCol"
ret = Related(columns="TestCol")
assert isinstance(ret.columns, list)
assert len(ret.columns) == 1
assert ret.columns[0] == "TestCol"

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 87e7ef8

Please sign in to comment.