PyAMF DatabaseError: 'This query is not supported by the database.' when returning the User object

428 views Asked by At

This is the error I'm getting:

ERROR    2011-11-19 04:19:55,441 django.py:164] Error encoding AMF request
Traceback (most recent call last):
  File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/remoting/gateway/django.py", line 161, in __call__
    logger=self.logger, timezone_offset=timezone_offset)
  File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/remoting/__init__.py", line 676, in encode
  File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/remoting/__init__.py", line 520, in _write_body
  File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/remoting/__init__.py", line 486, in _encode_body
  File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/codec.py", line 499, in writeElement
    func(data)
  File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/amf0.py", line 657, in writeAMF3
    self.context.getAMF3Encoder(self).writeElement(data)
  File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/codec.py", line 499, in writeElement
    func(data)
  File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/amf3.py", line 1456, in writeObject
    self.writeElement(value)
  File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/codec.py", line 499, in writeElement
    func(data)
  File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/amf3.py", line 1298, in writeList
    [self.writeElement(x) for x in n]
  File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/codec.py", line 499, in writeElement
    func(data)
  File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/codec.py", line 358, in __call__
    ret = self.func(data, encoder=self.encoder)
  File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/adapters/_django_db_models_base.py", line 276, in writeDjangoObject
    encoder.writeObject(referenced_object)
  File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/amf3.py", line 1468, in writeObject
    self.writeElement(value)
  File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/codec.py", line 499, in writeElement
    func(data)
  File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/codec.py", line 358, in __call__
    ret = self.func(data, encoder=self.encoder)
  File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/adapters/_django_db_models_base.py", line 276, in writeDjangoObject
    encoder.writeObject(referenced_object)
  File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/amf3.py", line 1468, in writeObject
    self.writeElement(value)
  File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/codec.py", line 499, in writeElement
    func(data)
  File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/codec.py", line 358, in __call__
    ret = self.func(data, encoder=self.encoder)
  File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/adapters/_django_db_models_base.py", line 276, in writeDjangoObject
    encoder.writeObject(referenced_object)
  File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/amf3.py", line 1447, in writeObject
    attrs = alias.getEncodableAttributes(obj, codec=self)
  File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/adapters/_django_db_models_base.py", line 173, in getEncodableAttributes
    attrs[name] = [x for x in getattr(obj, name).all()]
  File "/Users/bryce/Documents/Aptana Studio 3 Workspace/django-blog/django/db/models/query.py", line 107, in _result_iter
    self._fill_cache()
  File "/Users/bryce/Documents/Aptana Studio 3 Workspace/django-blog/django/db/models/query.py", line 774, in _fill_cache
    self._result_cache.append(self._iter.next())
  File "/Users/bryce/Documents/Aptana Studio 3 Workspace/django-blog/django/db/models/query.py", line 275, in iterator
    for row in compiler.results_iter():
  File "/Users/bryce/Documents/Aptana Studio 3 Workspace/DennysBE/djangotoolbox/db/basecompiler.py", line 225, in results_iter
    self.check_query()
  File "/Users/bryce/Documents/Aptana Studio 3 Workspace/DennysBE/djangotoolbox/db/basecompiler.py", line 273, in check_query
    raise DatabaseError('This query is not supported by the database.')
DatabaseError: This query is not supported by the database.

Here are my models that matter for this problem:

class ChallengeAct(models.Model):
    challenge = models.ForeignKey(Challenge, blank=True, null=True)
    user = models.ForeignKey(User, blank=True, null=True)
    start_date = models.DateTimeField(blank=True, null=True)
    progress_value = models.IntegerField(default=0)
    earned_coupon = models.ForeignKey(EarnedCoupon, blank=True, null=True)

Here is the method that causes the error:

def foo_bar(request):
    user = request.user
    c = ChallengeAct()
    c.challenge = Challenge.objects.get(id=1)
    c.start_date = datetime.now()
    c.progress_value = 1
    c.user = user
    c.save()

#    Here is where I set the user to null to avoid the DatabaseError
    c.user = None
    return [c]

The interesting thing is that I need to set the c.user = None right before I return it so I don't get the DatabaseError: This query is not supported by the database. problem.

--update-- The more I think about it, it seems like a pyamf and django-nonrel problem with getting the user object. I'm guessing that when pyamf tries to get the user object it is using some type of join query, which isn't supported on django-nonrel.

Why is this? Is there a way around it?

1

There are 1 answers

0
Oleksiy On

You should not have to to allow for blank=True, null=True for User model. Normally django.contrib.auth.models.AnonymousUser takes care of anonymous requests. It may or may not fix the issue, but it is worth trying, i.e.:

class ChallengeAct(RewardActBase):
    user = models.ForeignKey(User)
    ....