Skip to content

Commit

Permalink
fix blank/null validation in object update
Browse files Browse the repository at this point in the history
  • Loading branch information
vegu committed Oct 23, 2023
1 parent 003c9b0 commit e14b74c
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/peeringdb/_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,25 @@ def copy_object(self, new):
for field in self.backend.get_fields(new.__class__):
try:
setattr(old, field.name, getattr(new, field.name))
except TypeError:
pass # Ignore refs
self.backend.clean(old)
except TypeError as e:
if "Direct assignment" in str(e):
pass # Ignore refs

Check warning on line 44 in src/peeringdb/_update.py

View check run for this annotation

Codecov / codecov/patch

src/peeringdb/_update.py#L38-L44

Added lines #L38 - L44 were not covered by tests
else:
raise

Check warning on line 46 in src/peeringdb/_update.py

View check run for this annotation

Codecov / codecov/patch

src/peeringdb/_update.py#L46

Added line #L46 was not covered by tests

try:
self.backend.clean(old)
except self.backend.validation_error() as e:

Check warning on line 50 in src/peeringdb/_update.py

View check run for this annotation

Codecov / codecov/patch

src/peeringdb/_update.py#L48-L50

Added lines #L48 - L50 were not covered by tests
# e.message_dict contains field names as keys and lists of errors as values
for errors in e.message_dict.values():
for error in errors:

Check warning on line 53 in src/peeringdb/_update.py

View check run for this annotation

Codecov / codecov/patch

src/peeringdb/_update.py#L52-L53

Added lines #L52 - L53 were not covered by tests
# Checking if the error message is the one we want to ignore
# field is allowed to be None in the db, but not blank according to backend
# validation. We ignore this error since the data is already validated
# and writing None to the db is fine.
if error != "This field cannot be blank.":
raise e

Check warning on line 59 in src/peeringdb/_update.py

View check run for this annotation

Codecov / codecov/patch

src/peeringdb/_update.py#L58-L59

Added lines #L58 - L59 were not covered by tests

self.backend.save(old)

Check warning on line 61 in src/peeringdb/_update.py

View check run for this annotation

Codecov / codecov/patch

src/peeringdb/_update.py#L61

Added line #L61 was not covered by tests

def create_obj(self, row: dict, res) -> (any, bool):
Expand Down

0 comments on commit e14b74c

Please sign in to comment.