Problem with "pyamf.Undefined"

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with "pyamf.Undefined"

Clay Zhong
Hi all,

There's a problem when I using PyAMF 0.5, it always raise error:
ValueError: Cannot assign "pyamf.Undefined": "Company.city" must be a
"City" instance.

I suppose it's because Django lazy loading, so I add select_related(),
but still not working. Can anyone give me some advice?

Here is the relative code, hope it's useful.

* models.py
class Company(BaseModel):
    name = models.CharField(max_length=200, unique=True)
    phone = models.CharField(max_length=50, blank=True)
    address = models.CharField(max_length=500, blank=True)
    city = models.ForeignKey(City, blank=True, null=True)


* gateway.py
from pyamf import register_package
from lincoln.recruiting import models
register_package(models, 'lincoln.recruiting.models')

from lincoln.recruiting.view import company_view
company_services = {
    'companyService.list': company_view.list,
    'companyService.save': company_view.save,
    'companyService.delete': company_view.delete,
    'companyService.view': company_view.view
}

services = company_services
from pyamf.remoting.gateway.django import DjangoGateway
recruiting_gateway = DjangoGateway(services, debug=True)


* company_view.py
def list(request, data):
    return Company.objects.select_related().all()

def view(request, data):
    return Company.objects.select_related().get(id=data['id'])

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Problem with "pyamf.Undefined"

Ricardo Santos-5
I had the exact same issue.

>From the Django documentation:
"Note that, by default, select_related() does not follow foreign keys
that have null=True."

http://docs.djangoproject.com/en/dev/ref/models/querysets/#id4

This means you would solve your issue by using select_related('city').

Hope that helps.

Ricardo

On Mon, 2009-09-14 at 22:59 +0800, Clay Zhong wrote:

> Hi all,
>
> There's a problem when I using PyAMF 0.5, it always raise error:
> ValueError: Cannot assign "pyamf.Undefined": "Company.city" must be a
> "City" instance.
>
> I suppose it's because Django lazy loading, so I add select_related(),
> but still not working. Can anyone give me some advice?
>
> Here is the relative code, hope it's useful.
>
> * models.py
> class Company(BaseModel):
>     name = models.CharField(max_length=200, unique=True)
>     phone = models.CharField(max_length=50, blank=True)
>     address = models.CharField(max_length=500, blank=True)
>     city = models.ForeignKey(City, blank=True, null=True)
>
>
> * gateway.py
> from pyamf import register_package
> from lincoln.recruiting import models
> register_package(models, 'lincoln.recruiting.models')
>
> from lincoln.recruiting.view import company_view
> company_services = {
>     'companyService.list': company_view.list,
>     'companyService.save': company_view.save,
>     'companyService.delete': company_view.delete,
>     'companyService.view': company_view.view
> }
>
> services = company_services
> from pyamf.remoting.gateway.django import DjangoGateway
> recruiting_gateway = DjangoGateway(services, debug=True)
>
>
> * company_view.py
> def list(request, data):
>     return Company.objects.select_related().all()
>
> def view(request, data):
>     return Company.objects.select_related().get(id=data['id'])
>
> _______________________________________________
> PyAMF users mailing list - [hidden email]
> http://lists.pyamf.org/mailman/listinfo/users
_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Problem with "pyamf.Undefined"

Nick Joyce
In reply to this post by Clay Zhong
On 14 Sep 2009, at 15:59, Clay Zhong wrote:

> Hi all,
>
> There's a problem when I using PyAMF 0.5, it always raise error:
> ValueError: Cannot assign "pyamf.Undefined": "Company.city" must be a
> "City" instance.
>
> I suppose it's because Django lazy loading, so I add select_related(),
> but still not working. Can anyone give me some advice?
>
> Here is the relative code, hope it's useful.
>
> * models.py
> class Company(BaseModel):
>    name = models.CharField(max_length=200, unique=True)
>    phone = models.CharField(max_length=50, blank=True)
>    address = models.CharField(max_length=500, blank=True)
>    city = models.ForeignKey(City, blank=True, null=True)
>
>
> * gateway.py
> from pyamf import register_package
> from lincoln.recruiting import models
> register_package(models, 'lincoln.recruiting.models')
>
> from lincoln.recruiting.view import company_view
> company_services = {
>    'companyService.list': company_view.list,
>    'companyService.save': company_view.save,
>    'companyService.delete': company_view.delete,
>    'companyService.view': company_view.view
> }
>
> services = company_services
> from pyamf.remoting.gateway.django import DjangoGateway
> recruiting_gateway = DjangoGateway(services, debug=True)
>
>
> * company_view.py
> def list(request, data):
>    return Company.objects.select_related().all()
>
> def view(request, data):
>    return Company.objects.select_related().get(id=data['id'])
>
> _______________________________________________
> PyAMF users mailing list - [hidden email]
> http://lists.pyamf.org/mailman/listinfo/users

Does this only occur when a request received, rather than responding  
to the request?

A full stacktrace would be useful here and any logs/logging that you  
may have.

Thanks!

Nick

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Problem with "pyamf.Undefined"

Thijs Triemstra
Hi Clay,

please enable logging on your gateway and post the traceback/debug  
info here.

import logging

logging.basicConfig(level=logging.DEBUG)

from pyamf.remoting.gateway.django import DjangoGateway
recruiting_gateway = DjangoGateway(services, logger=logging, debug=True)

Thanks,

Thijs

On 14 Sep 2009, at 16:22, Nick Joyce wrote:

> On 14 Sep 2009, at 15:59, Clay Zhong wrote:
>
>> Hi all,
>>
>> There's a problem when I using PyAMF 0.5, it always raise error:
>> ValueError: Cannot assign "pyamf.Undefined": "Company.city" must be a
>> "City" instance.
>>
>> I suppose it's because Django lazy loading, so I add  
>> select_related(),
>> but still not working. Can anyone give me some advice?
>>
>> Here is the relative code, hope it's useful.
>>
>> * models.py
>> class Company(BaseModel):
>>   name = models.CharField(max_length=200, unique=True)
>>   phone = models.CharField(max_length=50, blank=True)
>>   address = models.CharField(max_length=500, blank=True)
>>   city = models.ForeignKey(City, blank=True, null=True)
>>
>>
>> * gateway.py
>> from pyamf import register_package
>> from lincoln.recruiting import models
>> register_package(models, 'lincoln.recruiting.models')
>>
>> from lincoln.recruiting.view import company_view
>> company_services = {
>>   'companyService.list': company_view.list,
>>   'companyService.save': company_view.save,
>>   'companyService.delete': company_view.delete,
>>   'companyService.view': company_view.view
>> }
>>
>> services = company_services
>> from pyamf.remoting.gateway.django import DjangoGateway
>> recruiting_gateway = DjangoGateway(services, debug=True)
>>
>>
>> * company_view.py
>> def list(request, data):
>>   return Company.objects.select_related().all()
>>
>> def view(request, data):
>>   return Company.objects.select_related().get(id=data['id'])
>>
>> _______________________________________________
>> PyAMF users mailing list - [hidden email]
>> http://lists.pyamf.org/mailman/listinfo/users
>
> Does this only occur when a request received, rather than responding  
> to the request?
>
> A full stacktrace would be useful here and any logs/logging that you  
> may have.
>
> Thanks!
>
> Nick
>
> _______________________________________________
> PyAMF users mailing list - [hidden email]
> http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users

PGP.sig (201 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Problem with "pyamf.Undefined"

Clay Zhong
Hi Thijs,

Here is the traceback:

pydev debugger: warning: psyco not available for speedups (the debugger will still work correctly, but a bit slower)
pydev debugger: starting
/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/util/imports.py:60: DeprecationWarning: the sets module is deprecated
Traceback (most recent call last):
  File "/home/clay/program/eclipse/plugins/org.python.pydev.debug_1.5.0.1251989166/pysrc/pydevd.py", line 953, in <module>
    debugger.run(setup['file'], None, None)
  File "/home/clay/program/eclipse/plugins/org.python.pydev.debug_1.5.0.1251989166/pysrc/pydevd.py", line 780, in run
    execfile(file, globals, locals) #execute the script
  File "/home/clay/work/lincoln/source/lincoln/src/lincoln/gateway_test.py", line 32, in <module>
    print company_service.list(queryParams)
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 55, in __call__
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 105, in _call
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 424, in execute_single
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 504, in _getResponse
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/remoting/__init__.py", line 663, in decode
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/remoting/__init__.py", line 477, in _read_body
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/__init__.py", line 901, in readElement
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/amf0.py", line 261, in readList
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/__init__.py", line 901, in readElement
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/amf0.py", line 286, in readTypedObject
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/amf0.py", line 333, in _readObject
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/__init__.py", line 748, in applyAttributes
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/util/__init__.py", line 862, in set_attrs
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/fields/related.py", line 264, in __set__
    self.field.name, self.field.rel.to._meta.object_name))
ValueError: Cannot assign "pyamf.Undefined": "Company.city" must be a "City" instance.
Exception AttributeError: "'NoneType' object has no attribute 'print_exc'" in <bound method __AptDpkgPackageInfo.__del__ of <apport.packaging_impl.__AptDpkgPackageInfo instance at 0xa86b6ec>> ignored

It works out by Ricardo's way, I change the select_related to Company.objects.select_related('city', 'city__province').all(), it works fine.
Thanks all you guys.

Clay

On Mon, 2009-09-14 at 18:55 +0100, Thijs Triemstra | Collab wrote:
Hi Clay,

please enable logging on your gateway and post the traceback/debug  
info here.

import logging

logging.basicConfig(level=logging.DEBUG)

from pyamf.remoting.gateway.django import DjangoGateway
recruiting_gateway = DjangoGateway(services, logger=logging, debug=True)

Thanks,

Thijs

On 14 Sep 2009, at 16:22, Nick Joyce wrote:

> On 14 Sep 2009, at 15:59, Clay Zhong wrote:
>
>> Hi all,
>>
>> There's a problem when I using PyAMF 0.5, it always raise error:
>> ValueError: Cannot assign "pyamf.Undefined": "Company.city" must be a
>> "City" instance.
>>
>> I suppose it's because Django lazy loading, so I add  
>> select_related(),
>> but still not working. Can anyone give me some advice?
>>
>> Here is the relative code, hope it's useful.
>>
>> * models.py
>> class Company(BaseModel):
>>   name = models.CharField(max_length=200, unique=True)
>>   phone = models.CharField(max_length=50, blank=True)
>>   address = models.CharField(max_length=500, blank=True)
>>   city = models.ForeignKey(City, blank=True, null=True)
>>
>>
>> * gateway.py
>> from pyamf import register_package
>> from lincoln.recruiting import models
>> register_package(models, 'lincoln.recruiting.models')
>>
>> from lincoln.recruiting.view import company_view
>> company_services = {
>>   'companyService.list': company_view.list,
>>   'companyService.save': company_view.save,
>>   'companyService.delete': company_view.delete,
>>   'companyService.view': company_view.view
>> }
>>
>> services = company_services
>> from pyamf.remoting.gateway.django import DjangoGateway
>> recruiting_gateway = DjangoGateway(services, debug=True)
>>
>>
>> * company_view.py
>> def list(request, data):
>>   return Company.objects.select_related().all()
>>
>> def view(request, data):
>>   return Company.objects.select_related().get(id=data['id'])
>>
>> _______________________________________________
>> PyAMF users mailing list - [hidden email]
>> http://lists.pyamf.org/mailman/listinfo/users
>
> Does this only occur when a request received, rather than responding  
> to the request?
>
> A full stacktrace would be useful here and any logs/logging that you  
> may have.
>
> Thanks!
>
> Nick
>
> _______________________________________________
> PyAMF users mailing list - [hidden email]
> http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Problem with "pyamf.Undefined"

Clay Zhong
In reply to this post by Thijs Triemstra
Hi Thijs,

Here is the traceback:

pydev debugger: warning: psyco not available for speedups (the debugger will still work correctly, but a bit slower)
pydev debugger: starting
/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/util/imports.py:60: DeprecationWarning: the sets module is deprecated
Traceback (most recent call last):
  File "/home/clay/program/eclipse/plugins/org.python.pydev.debug_1.5.0.1251989166/pysrc/pydevd.py", line 953, in <module>
    debugger.run(setup['file'], None, None)
  File "/home/clay/program/eclipse/plugins/org.python.pydev.debug_1.5.0.1251989166/pysrc/pydevd.py", line 780, in run
    execfile(file, globals, locals) #execute the script
  File "/home/clay/work/lincoln/source/lincoln/src/lincoln/gateway_test.py", line 32, in <module>
    print company_service.list(queryParams)
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 55, in __call__
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 105, in _call
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 424, in execute_single
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 504, in _getResponse
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/remoting/__init__.py", line 663, in decode
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/remoting/__init__.py", line 477, in _read_body
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/__init__.py", line 901, in readElement
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/amf0.py", line 261, in readList
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/__init__.py", line 901, in readElement
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/amf0.py", line 286, in readTypedObject
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/amf0.py", line 333, in _readObject
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/__init__.py", line 748, in applyAttributes
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/util/__init__.py", line 862, in set_attrs
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/fields/related.py", line 264, in __set__
    self.field.name, self.field.rel.to._meta.object_name))
ValueError: Cannot assign "pyamf.Undefined": "Company.city" must be a "City" instance.
Exception AttributeError: "'NoneType' object has no attribute 'print_exc'" in <bound method __AptDpkgPackageInfo.__del__ of <apport.packaging_impl.__AptDpkgPackageInfo instance at 0xa86b6ec>> ignored

It works out by Ricardo's way, I change the select_related to Company.objects.select_related('city', 'city__province').all(), it works fine.
Thanks all you guys.

Clay

On Mon, 2009-09-14 at 18:55 +0100, Thijs Triemstra | Collab wrote:
Hi Clay,

please enable logging on your gateway and post the traceback/debug  
info here.

import logging

logging.basicConfig(level=logging.DEBUG)

from pyamf.remoting.gateway.django import DjangoGateway
recruiting_gateway = DjangoGateway(services, logger=logging, debug=True)

Thanks,

Thijs

On 14 Sep 2009, at 16:22, Nick Joyce wrote:

> On 14 Sep 2009, at 15:59, Clay Zhong wrote:
>
>> Hi all,
>>
>> There's a problem when I using PyAMF 0.5, it always raise error:
>> ValueError: Cannot assign "pyamf.Undefined": "Company.city" must be a
>> "City" instance.
>>
>> I suppose it's because Django lazy loading, so I add  
>> select_related(),
>> but still not working. Can anyone give me some advice?
>>
>> Here is the relative code, hope it's useful.
>>
>> * models.py
>> class Company(BaseModel):
>>   name = models.CharField(max_length=200, unique=True)
>>   phone = models.CharField(max_length=50, blank=True)
>>   address = models.CharField(max_length=500, blank=True)
>>   city = models.ForeignKey(City, blank=True, null=True)
>>
>>
>> * gateway.py
>> from pyamf import register_package
>> from lincoln.recruiting import models
>> register_package(models, 'lincoln.recruiting.models')
>>
>> from lincoln.recruiting.view import company_view
>> company_services = {
>>   'companyService.list': company_view.list,
>>   'companyService.save': company_view.save,
>>   'companyService.delete': company_view.delete,
>>   'companyService.view': company_view.view
>> }
>>
>> services = company_services
>> from pyamf.remoting.gateway.django import DjangoGateway
>> recruiting_gateway = DjangoGateway(services, debug=True)
>>
>>
>> * company_view.py
>> def list(request, data):
>>   return Company.objects.select_related().all()
>>
>> def view(request, data):
>>   return Company.objects.select_related().get(id=data['id'])
>>
>> _______________________________________________
>> PyAMF users mailing list - [hidden email]
>> http://lists.pyamf.org/mailman/listinfo/users
>
> Does this only occur when a request received, rather than responding  
> to the request?
>
> A full stacktrace would be useful here and any logs/logging that you  
> may have.
>
> Thanks!
>
> Nick
>
> _______________________________________________
> PyAMF users mailing list - [hidden email]
> http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Problem with "pyamf.Undefined"

Clay Zhong
In reply to this post by Ricardo Santos-5
Hi guys,

Sorry to bother again, but it seems another issue occur with the
pyamf.register_package.

I solved the pyamf.Undefined problem with select all related attributes
when sending response data to front site. But later I found it's not
what I want, because each request, I have to load model's all foreign
attributes even if it's useless. For example, I just want to get a
company basic info, but I have to use:

Company.object.select_related('city', 'city__province')

It seems fine with only one foreign key in company, but what will happen
if the model has many foreign keys and each of them also has other
foreign keys. The lazy loading was totally discarded, it should be a
serious performance issue. Is there any way I can work around? How about
write another plain object instead of using django model directly?

And there's another problem when I use django.contrib.auth.models.User
in my model:

from django.contrib.auth.models import User
class UserProfile(BaseModel):
    user = models.ForeignKey(User, unique=True)
    phone = models.CharField(max_length=50, blank=True)
    cell_phone = models.CharField(max_length=50, blank=True)
    title = models.CharField(max_length=100, blank=True)
    login_times = models.IntegerField(default=0)
    last_login_ip = models.IPAddressField(blank=True)
    history = models.XMLField(blank=True)
    company = models.ForeignKey(Company)

Here is the traceback:

Traceback (most recent call last):
  File
"/home/clay/program/eclipse/plugins/org.python.pydev.debug_1.5.0.1251989166/pysrc/pydevd.py", line 953, in <module>
    debugger.run(setup['file'], None, None)
  File
"/home/clay/program/eclipse/plugins/org.python.pydev.debug_1.5.0.1251989166/pysrc/pydevd.py", line 780, in run
    execfile(file, globals, locals) #execute the script
  File
"/home/clay/work/lincoln/source/lincoln/src/lincoln/gateway_test.py",
line 37, in <module>
    print job.list(queryParams)
  File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 55, in __call__
  File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 105, in _call
  File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 424, in execute_single
  File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 504, in _getResponse
  File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/remoting/__init__.py", line 663, in decode
  File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/remoting/__init__.py", line 477, in _read_body
  File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/__init__.py", line 901, in readElement
  File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/amf0.py", line 346, in readObject
  File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/amf0.py", line 326, in _readObject
  File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/__init__.py", line 901, in readElement
  File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/amf0.py", line 261, in readList
  File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/__init__.py", line 901, in readElement
  File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/amf0.py", line 286, in readTypedObject
  File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/amf0.py", line 326, in _readObject
  File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/__init__.py", line 901, in readElement
  File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/amf0.py", line 286, in readTypedObject
  File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/amf0.py", line 333, in _readObject
  File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/__init__.py", line 748, in applyAttributes
  File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/util/__init__.py", line 862, in set_attrs
  File
"/usr/local/lib/python2.6/dist-packages/django/db/models/fields/related.py", line 264, in __set__
    self.field.name, self.field.rel.to._meta.object_name))
ValueError: Cannot assign "{'username': u'clay', 'first_name': u'',
'last_name': u'', 'is_active': 1, 'id': 1, 'is_superuser': 1,
'is_staff': 1, 'last_login': datetime.datetime(2009, 9, 17, 22, 5, 40),
'groups': [], 'user_permissions': [], 'password': u'sha1$322b0
$c1af64e426979f5c0dc2190596a5b89094a9e2b0', 'email':
u'[hidden email]', 'date_joined': datetime.datetime(2009, 9, 17, 22,
4, 34)}": "UserProfile.user" must be a "User" instance.
Exception AttributeError: "'NoneType' object has no attribute
'print_exc'" in <bound method __AptDpkgPackageInfo.__del__ of
<apport.packaging_impl.__AptDpkgPackageInfo instance at 0x985088c>>
ignored

Thanks for your attention and have a nice weekend.

Clay

On Mon, 2009-09-14 at 17:16 +0200, Ricardo Santos wrote:

> I had the exact same issue.
>
> >From the Django documentation:
> "Note that, by default, select_related() does not follow foreign keys
> that have null=True."
>
> http://docs.djangoproject.com/en/dev/ref/models/querysets/#id4
>
> This means you would solve your issue by using select_related('city').
>
> Hope that helps.
>
> Ricardo
>
> On Mon, 2009-09-14 at 22:59 +0800, Clay Zhong wrote:
> > Hi all,
> >
> > There's a problem when I using PyAMF 0.5, it always raise error:
> > ValueError: Cannot assign "pyamf.Undefined": "Company.city" must be a
> > "City" instance.
> >
> > I suppose it's because Django lazy loading, so I add select_related(),
> > but still not working. Can anyone give me some advice?
> >
> > Here is the relative code, hope it's useful.
> >
> > * models.py
> > class Company(BaseModel):
> >     name = models.CharField(max_length=200, unique=True)
> >     phone = models.CharField(max_length=50, blank=True)
> >     address = models.CharField(max_length=500, blank=True)
> >     city = models.ForeignKey(City, blank=True, null=True)
> >
> >
> > * gateway.py
> > from pyamf import register_package
> > from lincoln.recruiting import models
> > register_package(models, 'lincoln.recruiting.models')
> >
> > from lincoln.recruiting.view import company_view
> > company_services = {
> >     'companyService.list': company_view.list,
> >     'companyService.save': company_view.save,
> >     'companyService.delete': company_view.delete,
> >     'companyService.view': company_view.view
> > }
> >
> > services = company_services
> > from pyamf.remoting.gateway.django import DjangoGateway
> > recruiting_gateway = DjangoGateway(services, debug=True)
> >
> >
> > * company_view.py
> > def list(request, data):
> >     return Company.objects.select_related().all()
> >
> > def view(request, data):
> >     return Company.objects.select_related().get(id=data['id'])
> >
> > _______________________________________________
> > PyAMF users mailing list - [hidden email]
> > http://lists.pyamf.org/mailman/listinfo/users
> _______________________________________________
> PyAMF users mailing list - [hidden email]
> http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Problem with "pyamf.Undefined"

Jesse Warden-2
I had the same problem.  My simple Django User worked, and any construct without a foreign key.  Once I had to load some models, BUT not all their fields, it'd wig out.

On Sat, Sep 19, 2009 at 7:18 AM, Clay Zhong <[hidden email]> wrote:
Hi guys,

Sorry to bother again, but it seems another issue occur with the
pyamf.register_package.

I solved the pyamf.Undefined problem with select all related attributes
when sending response data to front site. But later I found it's not
what I want, because each request, I have to load model's all foreign
attributes even if it's useless. For example, I just want to get a
company basic info, but I have to use:

Company.object.select_related('city', 'city__province')

It seems fine with only one foreign key in company, but what will happen
if the model has many foreign keys and each of them also has other
foreign keys. The lazy loading was totally discarded, it should be a
serious performance issue. Is there any way I can work around? How about
write another plain object instead of using django model directly?

And there's another problem when I use django.contrib.auth.models.User
in my model:

from django.contrib.auth.models import User
class UserProfile(BaseModel):
   user = models.ForeignKey(User, unique=True)
   phone = models.CharField(max_length=50, blank=True)
   cell_phone = models.CharField(max_length=50, blank=True)
   title = models.CharField(max_length=100, blank=True)
   login_times = models.IntegerField(default=0)
   last_login_ip = models.IPAddressField(blank=True)
   history = models.XMLField(blank=True)
   company = models.ForeignKey(Company)

Here is the traceback:

Traceback (most recent call last):
 File
"/home/clay/program/eclipse/plugins/org.python.pydev.debug_1.5.0.1251989166/pysrc/pydevd.py", line 953, in <module>
   debugger.run(setup['file'], None, None)
 File
"/home/clay/program/eclipse/plugins/org.python.pydev.debug_1.5.0.1251989166/pysrc/pydevd.py", line 780, in run
   execfile(file, globals, locals) #execute the script
 File
"/home/clay/work/lincoln/source/lincoln/src/lincoln/gateway_test.py",
line 37, in <module>
   print job.list(queryParams)
 File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 55, in __call__
 File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 105, in _call
 File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 424, in execute_single
 File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 504, in _getResponse
 File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/remoting/__init__.py", line 663, in decode
 File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/remoting/__init__.py", line 477, in _read_body
 File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/__init__.py", line 901, in readElement
 File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/amf0.py", line 346, in readObject
 File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/amf0.py", line 326, in _readObject
 File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/__init__.py", line 901, in readElement
 File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/amf0.py", line 261, in readList
 File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/__init__.py", line 901, in readElement
 File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/amf0.py", line 286, in readTypedObject
 File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/amf0.py", line 326, in _readObject
 File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/__init__.py", line 901, in readElement
 File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/amf0.py", line 286, in readTypedObject
 File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/amf0.py", line 333, in _readObject
 File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/__init__.py", line 748, in applyAttributes
 File
"/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-i686.egg/pyamf/util/__init__.py", line 862, in set_attrs
 File
"/usr/local/lib/python2.6/dist-packages/django/db/models/fields/related.py", line 264, in __set__
   self.field.name, self.field.rel.to._meta.object_name))
ValueError: Cannot assign "{'username': u'clay', 'first_name': u'',
'last_name': u'', 'is_active': 1, 'id': 1, 'is_superuser': 1,
'is_staff': 1, 'last_login': datetime.datetime(2009, 9, 17, 22, 5, 40),
'groups': [], 'user_permissions': [], 'password': u'sha1$322b0
$c1af64e426979f5c0dc2190596a5b89094a9e2b0', 'email':
[hidden email]', 'date_joined': datetime.datetime(2009, 9, 17, 22,
4, 34)}": "UserProfile.user" must be a "User" instance.
Exception AttributeError: "'NoneType' object has no attribute
'print_exc'" in <bound method __AptDpkgPackageInfo.__del__ of
<apport.packaging_impl.__AptDpkgPackageInfo instance at 0x985088c>>
ignored

Thanks for your attention and have a nice weekend.

Clay

On Mon, 2009-09-14 at 17:16 +0200, Ricardo Santos wrote:
> I had the exact same issue.
>
> >From the Django documentation:
> "Note that, by default, select_related() does not follow foreign keys
> that have null=True."
>
> http://docs.djangoproject.com/en/dev/ref/models/querysets/#id4
>
> This means you would solve your issue by using select_related('city').
>
> Hope that helps.
>
> Ricardo
>
> On Mon, 2009-09-14 at 22:59 +0800, Clay Zhong wrote:
> > Hi all,
> >
> > There's a problem when I using PyAMF 0.5, it always raise error:
> > ValueError: Cannot assign "pyamf.Undefined": "Company.city" must be a
> > "City" instance.
> >
> > I suppose it's because Django lazy loading, so I add select_related(),
> > but still not working. Can anyone give me some advice?
> >
> > Here is the relative code, hope it's useful.
> >
> > * models.py
> > class Company(BaseModel):
> >     name = models.CharField(max_length=200, unique=True)
> >     phone = models.CharField(max_length=50, blank=True)
> >     address = models.CharField(max_length=500, blank=True)
> >     city = models.ForeignKey(City, blank=True, null=True)
> >
> >
> > * gateway.py
> > from pyamf import register_package
> > from lincoln.recruiting import models
> > register_package(models, 'lincoln.recruiting.models')
> >
> > from lincoln.recruiting.view import company_view
> > company_services = {
> >     'companyService.list': company_view.list,
> >     'companyService.save': company_view.save,
> >     'companyService.delete': company_view.delete,
> >     'companyService.view': company_view.view
> > }
> >
> > services = company_services
> > from pyamf.remoting.gateway.django import DjangoGateway
> > recruiting_gateway = DjangoGateway(services, debug=True)
> >
> >
> > * company_view.py
> > def list(request, data):
> >     return Company.objects.select_related().all()
> >
> > def view(request, data):
> >     return Company.objects.select_related().get(id=data['id'])
> >
> > _______________________________________________
> > PyAMF users mailing list - [hidden email]
> > http://lists.pyamf.org/mailman/listinfo/users
> _______________________________________________
> PyAMF users mailing list - [hidden email]
> http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users


_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Problem with "pyamf.Undefined"

Nick Joyce
In reply to this post by Clay Zhong
On 19 Sep 2009, at 12:18, Clay Zhong wrote:

> Hi guys,
>
> Sorry to bother again, but it seems another issue occur with the
> pyamf.register_package.
>
> I solved the pyamf.Undefined problem with select all related  
> attributes
> when sending response data to front site. But later I found it's not
> what I want, because each request, I have to load model's all foreign
> attributes even if it's useless. For example, I just want to get a
> company basic info, but I have to use:
>
> Company.object.select_related('city', 'city__province')
>
> It seems fine with only one foreign key in company, but what will  
> happen
> if the model has many foreign keys and each of them also has other
> foreign keys. The lazy loading was totally discarded, it should be a
> serious performance issue. Is there any way I can work around? How  
> about
> write another plain object instead of using django model directly?
>
> And there's another problem when I use django.contrib.auth.models.User
> in my model:
>
> from django.contrib.auth.models import User
> class UserProfile(BaseModel):
>   user = models.ForeignKey(User, unique=True)
>   phone = models.CharField(max_length=50, blank=True)
>   cell_phone = models.CharField(max_length=50, blank=True)
>   title = models.CharField(max_length=100, blank=True)
>   login_times = models.IntegerField(default=0)
>   last_login_ip = models.IPAddressField(blank=True)
>   history = models.XMLField(blank=True)
>   company = models.ForeignKey(Company)
>
> Here is the traceback:
>
> Traceback (most recent call last):
> File
> "/home/clay/program/eclipse/plugins/
> org.python.pydev.debug_1.5.0.1251989166/pysrc/pydevd.py", line 953,  
> in <module>
>   debugger.run(setup['file'], None, None)
> File
> "/home/clay/program/eclipse/plugins/
> org.python.pydev.debug_1.5.0.1251989166/pysrc/pydevd.py", line 780,  
> in run
>   execfile(file, globals, locals) #execute the script
> File
> "/home/clay/work/lincoln/source/lincoln/src/lincoln/gateway_test.py",
> line 37, in <module>
>   print job.list(queryParams)
> File
> "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-
> i686.egg/pyamf/remoting/client/__init__.py", line 55, in __call__
> File
> "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-
> i686.egg/pyamf/remoting/client/__init__.py", line 105, in _call
> File
> "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-
> i686.egg/pyamf/remoting/client/__init__.py", line 424, in  
> execute_single
> File
> "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-
> i686.egg/pyamf/remoting/client/__init__.py", line 504, in _getResponse
> File
> "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-
> i686.egg/pyamf/remoting/__init__.py", line 663, in decode
> File
> "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-
> i686.egg/pyamf/remoting/__init__.py", line 477, in _read_body
> File
> "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-
> i686.egg/pyamf/__init__.py", line 901, in readElement
> File
> "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-
> i686.egg/pyamf/amf0.py", line 346, in readObject
> File
> "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-
> i686.egg/pyamf/amf0.py", line 326, in _readObject
> File
> "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-
> i686.egg/pyamf/__init__.py", line 901, in readElement
> File
> "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-
> i686.egg/pyamf/amf0.py", line 261, in readList
> File
> "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-
> i686.egg/pyamf/__init__.py", line 901, in readElement
> File
> "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-
> i686.egg/pyamf/amf0.py", line 286, in readTypedObject
> File
> "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-
> i686.egg/pyamf/amf0.py", line 326, in _readObject
> File
> "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-
> i686.egg/pyamf/__init__.py", line 901, in readElement
> File
> "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-
> i686.egg/pyamf/amf0.py", line 286, in readTypedObject
> File
> "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-
> i686.egg/pyamf/amf0.py", line 333, in _readObject
> File
> "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-
> i686.egg/pyamf/__init__.py", line 748, in applyAttributes
> File
> "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5-py2.6-linux-
> i686.egg/pyamf/util/__init__.py", line 862, in set_attrs
> File
> "/usr/local/lib/python2.6/dist-packages/django/db/models/fields/
> related.py", line 264, in __set__
>   self.field.name, self.field.rel.to._meta.object_name))
> ValueError: Cannot assign "{'username': u'clay', 'first_name': u'',
> 'last_name': u'', 'is_active': 1, 'id': 1, 'is_superuser': 1,
> 'is_staff': 1, 'last_login': datetime.datetime(2009, 9, 17, 22, 5,  
> 40),
> 'groups': [], 'user_permissions': [], 'password': u'sha1$322b0
> $c1af64e426979f5c0dc2190596a5b89094a9e2b0', 'email':
> u'[hidden email]', 'date_joined': datetime.datetime(2009, 9, 17, 22,
> 4, 34)}": "UserProfile.user" must be a "User" instance.
> Exception AttributeError: "'NoneType' object has no attribute
> 'print_exc'" in <bound method __AptDpkgPackageInfo.__del__ of
> <apport.packaging_impl.__AptDpkgPackageInfo instance at 0x985088c>>
> ignored
>
> Thanks for your attention and have a nice weekend.
>
> Clay
Hi,

Can you apply this patch and tell me if it gets any better?

Thanks

Nick

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users

pyamf-django-empty-relation-659.diff (557 bytes) Download Attachment