#24690: ArrayField data bleeds between instances when using field.append(item)
-------------------------------------+-------------------------------------
Reporter: redbeard0x0a | Owner:
Type: Bug | Status: closed
Component: contrib.postgres | Version: 1.8
Severity: Release blocker | Resolution:
| worksforme
Keywords: ArrayField postgres | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by mjtamlyn):
* status: new => closed
* resolution: => worksforme
Comment:
The issue in your example code is that you have used `default=[]`. This
default is shared between all instances and in this case it is mutable, so
you are modifying the default array.
The correct code is to use `default=list`.
I don't consider this a bug in Django - this is the same behaviour as you
would get if you have code like:
{{{
def myfunc(foo, bar=[]):
bar.append(foo)
return bar
}}}
The first call to `myfunc(1)` would return `[1]`, the second `[1, 1]`,
etc.
--
Ticket URL: <https://code.djangoproject.com/ticket/24690#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/070.e6ccb112e8e4c94b9ce5816187fcfd82%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.