django-nonrel / djangotoolbox

Django tools for building nonrel backends

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nonetype object has no attribute 'model'

fatboystring opened this issue · comments

commented

I have been trying to get a blogging system running on GAE. I am not familiar with GAE or BigTable (although I am comfortable using Django) so please bare with me.

I followed the instructions here (and have my app running):

http://djangoappengine.readthedocs.org/en/latest/

However, when I try to use the 'ArchiveIndexView' class based generic view the app throws an exception (Nonetype object has no attribute 'model'). Having dug about a bit I notice the following:

  • the 'get_selected_fields' method in 'basecompiler.py' is called twice per http request;
  • the first time it is called, query.select_fields == [];
  • the second time it is called, query.select_fields == [None]

This seems to be the route of the problem. I was wondering if this is a known issue, or if I have missed something along the way.

The View:

class ListingView(ArchiveIndexView):

    model = Post

    date_field = "created_date"

    date_type = 'year'

    allow_future = False

The Model:

class Post(models.Model):

    # Post title
    title = models.CharField(max_length=250)

    # Url safe title for the post
    url_safe_title = models.SlugField(max_length=250)

    # Post content 
    content = models.TextField()

    # Post created date 
    created_date = models.DateTimeField(auto_now_add=True)

    # Post updated date
    updated_date = models.DateTimeField(auto_now=True)

    # Store a reference to the user
    author = models.ForeignKey(User)

    # Method for getting an absolute url for the resource
    def get_absolute_url(self, *args, **kwargs):
        return reverse('admin-post-update', args=[self.id,])

    # Method for getting a delete url for the resource
    def get_delete_url(self, *args, **kwargs):
        return ""

    # Method for getting a listing url for our resources
    @staticmethod
    def get_listing_url():
        return reverse('admin-post-list')

    # Convenience method for generating
    # a friendly unicode representation
    # of the instance 
    def __unicode__(self):
        return self.title

Also, please find the application stacktrace below:

ERROR 2014-01-27 12:20:04,084 base.py:212] Internal Server Error: /blog/
Traceback (most recent call last):
File "/Users/danielstringer/Dev/AppEngine/blog/django/core/handlers/base.py", line 115, in get_response
response = callback(request, _callback_args, *_callback_kwargs)
File "/Users/danielstringer/Dev/AppEngine/blog/django/views/generic/base.py", line 68, in view
return self.dispatch(request, _args, *_kwargs)
File "/Users/danielstringer/Dev/AppEngine/blog/django/views/generic/base.py", line 86, in dispatch
return handler(request, _args, *_kwargs)
File "/Users/danielstringer/Dev/AppEngine/blog/django/views/generic/dates.py", line 333, in get
self.date_list, self.object_list, extra_context = self.get_dated_items()
File "/Users/danielstringer/Dev/AppEngine/blog/django/views/generic/dates.py", line 412, in get_dated_items
date_list = self.get_date_list(qs, ordering='DESC')
File "/Users/danielstringer/Dev/AppEngine/blog/django/views/generic/dates.py", line 391, in get_date_list
if date_list is not None and not date_list and not allow_empty:
File "/Users/danielstringer/Dev/AppEngine/blog/django/db/models/query.py", line 157, in nonzero
return type(self).bool(self)
File "/Users/danielstringer/Dev/AppEngine/blog/django/db/models/query.py", line 151, in bool
next(iter(self))
File "/Users/danielstringer/Dev/AppEngine/blog/django/db/models/query.py", line 139, in _result_iter
self._fill_cache()
File "/Users/danielstringer/Dev/AppEngine/blog/django/db/models/query.py", line 941, in _fill_cache
self._result_cache.append(next(self._iter))
File "/Users/danielstringer/Dev/AppEngine/blog/djangotoolbox/db/basecompiler.py", line 375, in results_iter
fields = self.get_fields()
File "/Users/danielstringer/Dev/AppEngine/blog/djangotoolbox/db/basecompiler.py", line 519, in get_fields
if field.model._meta != query_model._meta:
AttributeError: 'NoneType' object has no attribute 'model'
INFO 2014-01-27 12:20:04,314 dev_appserver.py:3090] "GET /blog/ HTTP/1.1" 500 -

I would be more than happy to help diagnose and fix this issue (if the issue is in the djangotoolbox codebase). I am interested in your thoughts.

Many thanks,
Dan

I've never used the generic.ArchiveIndexView class, so I'm not sure exactly what it does. The best way to debug this would be to see what kind of query the class is trying to generate. You can do this by calling str(queryset.query) using the queryset object that the view class created and it should print out the sql query that it intends to generate. You hopefully should be able to figure out whats going wrong from there.

It could be an issue in djangotoolbox or in djangoappengine. Also, if you can reduce it to a simple testcase, you can upload that and I can try to debug it also.