[prev in list] [next in list] [prev in thread] [next in thread]
List: pyamf-tickets
Subject: Re: [pyamf-tickets] #556: Saving and obj created from Flex sets id
From: tickets () pyamf ! org
Date: 2009-05-21 0:11:12
Message-ID: 047.b57110172b8e4462bb056a9e70d90698 () pyamf ! org
[Download RAW message or body]
[Attachment #2 (text/plain)]
#556: Saving and obj created from Flex sets id to 0
------------------------+---------------------------------------------------
Reporter: aleperalta | Owner: nick
Type: defect | Status: new
Priority: major | Milestone: 0.6
Component: Remoting | Version: 0.4.2
Keywords: | Revfixed:
Branch: | Author:
------------------------+---------------------------------------------------
Description changed by thijs:
Old description:
> When creating and object which represents an instance of a django model
> from Flex/AIR the id atribute, which is usually typed int, is set to 0.
> Django expects None in the id attribute. But
> because it receives 0 django saves the object (and overwrites if one
> existed previously) in the database with id = 0.
>
> Tried setting int id to undefined, null or NaN does not work. (AIR/Flex
> doesn't like int to be set to null)
>
> My Work around:
>
> {{{
> from django.db import models
>
> class MyClass(models.Model):
> my_attr = model.CharField()
>
> #
> # Using the twistedserver from the example
> #
> pyamf.register_class(MyClass, '%s.%s' % (NAMESPACE, 'MyClass'))
>
> def my_service(obj):
> if obj.id == O:
> obj.id = None
> obj.save()
> return obj
>
> }}}
>
> njoyce's patch:
>
> {{{
> Index: pyamf/adapters/_django_db_models_base.py
> ===================================================================
> --- pyamf/adapters/_django_db_models_base.py (revision 2410)
> +++ pyamf/adapters/_django_db_models_base.py (working copy)
> @@ -61,8 +61,11 @@
> if value is pyamf.Undefined:
> return fields.NOT_PROVIDED
>
> - # deal with dates
> - if isinstance(field, fields.DateTimeField):
> + if isinstance(field, fields.AutoField):
> + if value == 0:
> + return None
> + elif isinstance(field, fields.DateTimeField):
> + # deal with dates
> return value
> elif isinstance(field, fields.DateField):
> return datetime.date(value.year, value.month, value.day
> }}}
New description:
When creating and object which represents an instance of a django model
from Flex/AIR the id atribute, which is usually typed int, is set to 0.
Django expects None in the id attribute. But
because it receives 0 django saves the object (and overwrites if one
existed previously) in the database with id = 0.
Tried setting int id to undefined, null or NaN does not work. (AIR/Flex
doesn't like int to be set to null)
My Work around:
{{{
#!python
from django.db import models
class MyClass(models.Model):
my_attr = model.CharField()
#
# Using the twistedserver from the example
#
pyamf.register_class(MyClass, '%s.%s' % (NAMESPACE, 'MyClass'))
def my_service(obj):
if obj.id == O:
obj.id = None
obj.save()
return obj
}}}
njoyce's patch:
{{{
Index: pyamf/adapters/_django_db_models_base.py
===================================================================
--- pyamf/adapters/_django_db_models_base.py (revision 2410)
+++ pyamf/adapters/_django_db_models_base.py (working copy)
@@ -61,8 +61,11 @@
if value is pyamf.Undefined:
return fields.NOT_PROVIDED
- # deal with dates
- if isinstance(field, fields.DateTimeField):
+ if isinstance(field, fields.AutoField):
+ if value == 0:
+ return None
+ elif isinstance(field, fields.DateTimeField):
+ # deal with dates
return value
elif isinstance(field, fields.DateField):
return datetime.date(value.year, value.month, value.day
}}}
--
--
PyAMF - Ticket URL: <http://pyamf.org/ticket/556#comment:4>
_______________________________________________
PyAMF tickets mailing list - tickets@pyamf.org
http://lists.pyamf.org/mailman/listinfo/tickets
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic