From dc604ac442da8ff5fdffa0278e0043cbaf63dd01 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 14 Aug 2021 18:53:56 +0200 Subject: [PATCH] Exception.message was deprecated in Python 2.6 and removed in Python 3 `BaseException.message` was deprecated as of Python 2.6 and is removed in Python 3. Use `str(e)` to access the user-readable message. Use `e.args` to access arguments passed to the exception. $ `python3` ``` >>> dir(Exception('Hey')) ['__cause__', '__class__', '__context__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__suppress_context__', '__traceback__', 'args', 'with_traceback'] >>> try: ... blah ... except Exception as e: ... print(e) ... print(e.args) ... print(e.message) # Will cause a second Exception ... name 'blah' is not defined ("name 'blah' is not defined",) Traceback (most recent call last): File "", line 2, in NameError: name 'blah' is not defined During handling of the above exception, another exception occurred: Traceback (most recent call last): File "", line 6, in AttributeError: 'NameError' object has no attribute 'message' ``` --- netbox/netbox/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox/netbox/models.py b/netbox/netbox/models.py index fce15c1f7..f1a528ade 100644 --- a/netbox/netbox/models.py +++ b/netbox/netbox/models.py @@ -115,7 +115,7 @@ class CustomFieldsMixin(models.Model): try: custom_fields[field_name].validate(value) except ValidationError as e: - raise ValidationError(f"Invalid value for custom field '{field_name}': {e.message}") + raise ValidationError(f"Invalid value for custom field '{field_name}': {e}") # Check for missing required values for cf in custom_fields.values():