tags:

views:

80

answers:

2

Hi there,

I have a simple python method that should be returned by Django/pyAMF but it's returning HTTP Status 500 instead (although I do pass through the method with no error and the Grupo object is created):

def newGrupo(request, igID):  
    return { 'grupo': Grupo.objects.create(ig = Ig.objects.get(pk=igID)),
             'membros' : None,
             'reponsavel' : None
        }

The weirdest thing is that another call that do almost the same thing (it actually returns a list of the previous) return ok:

def listGrupos(request, igID):
    result = []
    for grupo in Grupo.objects.filter(ig=igID):
        grp = {}
        grp['grupo'] = grupo
        grp['membros'] = grupo.membro_set.filter(ativo=True)
        grp['responsavel'] = grupo.responsavel
        result.append(grp)

    return result

Any idea why?

+1  A: 

Set the logger on the gateway, e.g.:

import logging

from pyamf.remoting.gateway.django import DjangoGateway

services = {}

gw = DjangoGateway(services, logger=logging)

This should help you to get to the root of the problem.

njoyce
Although it shows me the error message (Class objects cannot be serialised) It does not make any sense since I'm using the very same classes successfully in other calls.
Sam
A: 

Sounds like a problem with the pyAMF serializer for Django objects.

It works with "model.object.filter" but not with ".create" or ".get".

using "primitives" instead of Django objects avoid the problem:

 return { 'grupo': {"id": g.id},
             'membros' : None,
             'reponsavel' : None
        }
Sam
In time: the logging tip saved my day :) ... from the log to the source to the workaround, maybe to a patch ( some day ;)
Sam
What version of Django are you using? I know that some updates to PyAMF were required to support (the upcoming) 1.2, see http://dev.pyamf.org/ticket/759 for more.
njoyce