About Mutable Class Attributes
Mutable objects are lists, dictionaries, sets, user-defined classes, and combinations of all of these.
Be aware that modified mutable class attributes have impact on all instances of that class, and that can have unexpected behaviours:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
Moreover, if you use mutable class attributes for Django forms, the modifications of the attribute might affect not only this request, but also the future requests until the web server is restarted.
To avoid the unexpected behaviour, make the attribute instance-based:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
Tips and Tricks Programming Django 5.x Django 4.2 Django 3.2 Python 3
Also by me
Django Paddle Subscriptions app
For Django-based SaaS projects.
Django GDPR Cookie Consent app
For Django websites that use cookies.