Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8625535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:48:42+00:00 2026-06-12T07:48:42+00:00

Trying to get the groupby filter to work I’m getting an Atribute error. My

  • 0

Trying to get the groupby filter to work I’m getting an Atribute error. My groupby code looks like:

{% for year, year_purchases in purchases|groupby('PurchaseDate.year')|reverse %}
            <h2 class="year">{{ year }}</h2>
            {% for ... %}
            {% endfor %}
{% endfor %}

Where purchases is a list of PurchaseEntity:

class PurchaseEntity:
    def __init__(self):
        self.PurchaseDate = ''
        self.Orders = []

    def load_from_query(self,result):
        self.PurchaseDate = result.PurchaseDate

I’m getting the following error:

AttributeError
AttributeError: PurchaseEntity instance has no attribute '__getitem__'

The problem seems to be in environment.py:

def getitem(self, obj, argument):
"""Get an item or attribute of an object but prefer the item."""
try:
    return obj[argument]
except (TypeError, LookupError): #<-- Here it raises the error
    if isinstance(argument, basestring): #<-- It never reaches here
        try:
            attr = str(argument)
        except Exception:
            pass
        else:
            try:
                return getattr(obj, attr)
            except AttributeError:
                pass
    return self.undefined(obj=obj, name=argument)

I don’t think that its a Jinja2 or “groupby” error, because the getitem funcion is used everywhere. I googled it and couldn’t fint anything related. However, what I did is change the “except (TypeError, LookupError):” line and It worked with any this alternatives:

except:
except Exception:

I don’t know if my class delcaration is wrong or if I’m just missing something, because I tried with other clases (created by SQLAlchemy with autoload) and it worked fine. Any suggestions?

Btw, the arguments sent to getitem are:

>>> (obj,argument)
(<project.logic.purchase.PurchaseEntity instance at 0x050DF148>, 'PurchaseDate')
>>> obj.PurchaseDate
datetime.datetime(2012, 9, 25, 17, 1, 44)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:48:43+00:00Added an answer on June 12, 2026 at 7:48 am

    Try making PurchaseEntity extend object:

    class PurchaseEntity(object):
    

    Basic classes that do not extend anything throw an AttributeError when you try to lookup an item and they do not have it. Objects throw TypeError.

    >>> class Foo:
    ...     def foo(self):
    ...             void    
    ... 
    >>> class Bar(object):
    ...     def bar(self):
    ...             void
    ... 
    >>> foo = Foo()
    >>> bar = Bar()
    >>> foo['foo']
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: Foo instance has no attribute '__getitem__'
    >>> bar['bar']
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: 'Bar' object has no attribute '__getitem__'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get this LINQ to work but fails with the error. Cannot
I am trying get Struts 2 and Tiles to work and I am using
Trying to get this expression to work, can someone look at it and tell
I've spent hours trying to debug this code. I want to get the second-to-last
I'm trying to get an average for a count on a groupBy by joining
So i am trying get 2 div-containers which both should contain centered text (Both
I'm trying get the visible portion of UIImage from an UIImageView . UIImageView takes
I am trying get all html links within a string and replace them using
I am trying get all html links within a string and replace them using
Trying to get a wildcard search to pick up on any text in org_name

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.