﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31143	Variable attribute resolution priority in templates.	Vasili Korol	nobody	"Assume a Django model defining a `__getitem__` method:

{{{
class DataBlob ( models.Model ) :

    # ... field & method definitions ...

    def get ( self, key ) :
         """"""Returns a value by key from a msgpacked structure stored in a file.
         """"""
         # ....

    def __getitem__ ( self, key ) :
        """"""Just a convenience shortcut for a method DataBlob.get.
        """"""
        return self.get( key )
}}}

Now, we would like to access the `id` of a `DataBlob` instance in a template:

{{{
<input type=""hidden"" id=""VAL_datablob_id"" value=""{{datablob.id}}"">
}}}

Expected result in the `value` property of the `<input>`:  The id of the object.
Observed:    The result of calling `datablob['id']`.

The logic in `django.template.base.Variable._resolve_lookup` is to first attempt a dictinary lookup, and then fallback to attribute lookup.

Why is it prioritized this way? In the current implementation, the ""dictionary-interpreted"" keys will take precedence over object attributes, masking them completely if the names are the same. I think it is more logical to give priority to the attributes.

(I selected version 1.11 for this ticket, but i think it's the same for 2.2 and 3.0)."	Uncategorized	closed	Template system	dev	Normal	wontfix	template, variable resolving		Unreviewed	0	0	0	0	0	0
