views:

436

answers:

2

So far, I've had great success using PyAMF to communicate between my Flex front-end and my Django back-end. However, I believe I've encountered a bug. The following example (emphasis on the word "example") demonstrates the (potential) bug:

My Flex app contains the following VO:

package myproject.model.vo
{
    [Bindable]
    [RemoteClass(alias="myproject.models.Book")]

    public class BookVO
    {
        public var id:int;
        public var title:String;
        public var numberOfOddPages:int;
    }
}

My Django app contains the following model:

class Book(models.Models):
    title = models.CharField(max_length=20)

    def _get_number_of_odd_pages(self):
        #some code that calculates odd pages
       return odd_page_total

    numberOfOddPages = property(_get_number_of_odd_pages)

When I attempt to retrieve the book objects to display in a DataGrid, the books display in the grid as expected. However, "numberOfOddPages" is always set to 0. I have even attempted to explicitly set this attribute with a default value (i.e., "numberOfOddPages=100") to see if my "_get_number_of_odd_pages()" method had an error in it. Unfortunately, it yields the same result: the value in the VO remains at 0.

Does anyone have any insight into what I may be doing wrong?

A: 

Not at all.

Do you think the error is from Django or from Flex? You could first of all trace the AMF Object in Flex. If the value there is allready 0 then have a good look what PyAMF does.

monkee
+1  A: 

I just received the following response from PyAMF's lead developer. It's definitely a bug:

This is a bug in the way the Django adapter handles non models.fields.* properties.

If I do:

import pyamf

class Book(object):    
def _get_number_of_odd_pages(self):
  return 52

numberOfOddPages = property(_get_number_of_odd_pages)

pyamf.register_class(Book, 'Book')

encoded = pyamf.encode(Book()).getvalue() 
print pyamf.decode(encoded).next().numberOfOddPages

Then i get the correct values of 52.

I have created a ticket for this and will look into getting a patch a little later.

Cheers,

Nick

UPDATE: Nick has fixed this bug and it will be released in PyAMF 0.4.1 (which should be released this weekend).

Huuuze