#21765: Contexts cannot be compared for equality.
-------------------------------------+-------------------------------------
     Reporter:  Keryn Knight         |                    Owner:  onjin
  <django@…>                         |                   Status:  new
         Type:  New feature          |                  Version:  master
    Component:  Template system      |               Resolution:
     Severity:  Normal               |             Triage Stage:  Accepted
     Keywords:                       |      Needs documentation:  0
    Has patch:  0                    |  Patch needs improvement:  0
  Needs tests:  0                    |                    UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------
Changes (by Keryn Knight <django@…>):

 * status:  closed => new
 * resolution:  fixed =>


Comment:

 Re-opening with permission:
 The fix as committed is not entirely correct, I don't think, as it only
 compares the '''last''' state change of a given context, so comparisons
 can incorrectly return as equal if context states drift and then re-align,
 for example:
 {{{
 >>> import django
 >>> from django.template import Context
 >>> a = Context()
 >>> b = Context()
 >>> a == b
 True
 }}}
 the above is correct; from here on out, the contexts are continuations of
 the above example:
 {{{
 >>> a.update({'a': 1})
 >>> a == b
 False
 }}}
 that's also correct.
 {{{
 >>> a.update({'c': 3})
 >>> b.update({'c': 3})
 >>> a == b
 True
 }}}
 This is where the incorrectness appears. They are ''not equal'', but their
 last push to the stack was, so they're being treated as equal. Based on
 the commit in question (`d97bf2e9c8971764690caaf81a0914bc368d6b02`), the
 change would be going from:
 {{{
 return self.dicts[-1] == other.dicts[-1]
 }}}
 to
 {{{
 return self.dicts == other.dicts
 }}}
 which would at least ensure the rest of the context is taken into account,
 though that fix in itself may not be as correct as it should be -- it is
 '''strict''' in the sense that the entire history of the contexts being
 compared must be aligned, where it should perhaps instead squash the stack
 into one dictionary for both sides and compare ''them'' for equality.

 (Whether or not strictness is a benefit or problem is probably a DDN, and
 like testing equality for context subclasses which differ (or have
 different attrs, for things like `RenderContext`) could probably be
 tracked in separate tickets, though.)

-- 
Ticket URL: <https://code.djangoproject.com/ticket/21765#comment:5>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/095.772c4faffd611fb3e5aca8bfb82e9661%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to