1

After deploying AskBot I observe an unusual error:

AttributeError at /settings/QA_SITE_SETTINGS/
'SortedDict' object has no attribute 'insert'

This is the result of the following code:

langs_dict = SortedDict(django_settings.LANGUAGES)
default_code = django_settings.LANGUAGE_CODE
default_name = langs_dict[default_code]
langs_dict.insert(0, default_code, default_name) 

According to Django wiki, SortedDict seems to have insert method.

Any idea?

Here is the complete error page.
Related: AskBot bug.

Amir Gonnen
  • 3,525
  • 4
  • 32
  • 61
  • 1
    From the wiki page you linked: «SortedDict is deprecated as of Django 1.7 and will be removed in Django 1.9. Use [​collections.OrderedDict](http://docs.python.org/3/library/collections.html#collections.OrderedDict) instead.» Herein lies the fix, I suppose. – 9000 Oct 28 '15 at 16:00
  • @9000 Django version is 1.7.10, therefore should still be supported although deprecated. Do you think it's a Django bug? – Amir Gonnen Oct 28 '15 at 16:01
  • No, it's not a bug in Django. The `inserted` method was deprecated then removed. The problem is in AskBot. – Alasdair Oct 28 '15 at 16:32

1 Answers1

1

The SortedDict.insert method was deprecated in Django 1.5, and removed in Django 1.7. The wiki page you linked to was out of date, so I removed the mention of the insert method from there.

SortedDict itself is deprecated in Django 1.7, and will be removed in Django 1.9.

Now that Django only supports Python 2.7+, the correct fix is to use collections.OrderedDict instead of SortedDict.

Alasdair
  • 298,606
  • 55
  • 578
  • 516