In Django 4.1 alpha it looks like this:
errors = {}
if exclude is None:
exclude = set()
else:
exclude = set(exclude)
try:
self.clean_fields(exclude=exclude)
except ValidationError as e:
errors = e.update_error_dict(errors)
My model tests fail:
======================================================================
ERROR: test_username_too_long_exception_4 (speedy.core.accounts.tests.test_models.ReservedUsernameHebrewTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "D:\Uri\Speedy_Net\Git\speedy-net-public\speedy\core\accounts\tests\test_models.py", line 395, in test_username_too_long_exception_4
reserved_username.save()
File "D:\Uri\Speedy_Net\Git\speedy-net-public\speedy\core\base\models.py", line 21, in save
return super().save(*args, **kwargs)
File "D:\Uri\Speedy_Net\Git\speedy-net-public\speedy\core\base\models.py", line 12, in save
self.full_clean()
File "D:\Uri\Speedy_Net\Git\speedy-net-public\.venv_3.9\lib\site-packages\django\db\models\base.py", line 1464, in full_clean
self.clean_fields(exclude=exclude)
File "D:\Uri\Speedy_Net\Git\speedy-net-public\speedy\core\accounts\models.py", line 182, in clean_fields
exclude += ['username', 'slug']
TypeError: unsupported operand type(s) for +=: 'set' and 'list'
----------------------------------------------------------------------
What is the best written code to change the line `exclude += ['username', 'slug']` in my code? Is it `exclude |= set(['username', 'slug'])` or `exclude |= {'username', 'slug'}`? Or should I convert to list and then back to set?
What is the reason `exclude` was changed to a set?
Thanks,
Uri.
אורי