Skip to content

Commit

Permalink
fix: _parent and _sub_institution args not allowed in initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
galacticglum committed Apr 11, 2023
1 parent 6c23a5f commit 91f8db7
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/gator/core/models/institution.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,16 @@ class Institution(Document):

def __init__(self, **kwargs: Any) -> None:
"""Initialize an institution."""
# Don't allow the user to set the parent or sub-institutions directly
assert '_parent' not in kwargs, 'Use `parent` instead of `_parent`'
assert '_sub_institutions' not in kwargs, \
'Use `sub_institutions` instead of `_sub_institutions`'

# Prefer the parent and sub-institutions arguments over the
# _parent and _sub_institutions arguments
parent = kwargs.pop('parent', None)
if parent is None:
parent = kwargs.pop('_parent', None)

sub_institutions = kwargs.pop('sub_institutions', [])
if not sub_institutions:
sub_institutions = kwargs.pop('_sub_institutions', [])

super().__init__(**kwargs)

# Set the parent and sub-institutions
Expand Down

0 comments on commit 91f8db7

Please sign in to comment.