How can I use Flex to access foreign-keyed fields in Django?

View: New views
18 Messages — Rating Filter:   Alert me  

How can I use Flex to access foreign-keyed fields in Django?

by huuuze@gmail.com :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I need some help!  Please see the question I posted here:

http://stackoverflow.com/questions/481110/how-can-i-use-flex-to-access-foreign-keyed-fields-in-django

Does anyone know of a solution?  The one posted in the thread results in the following error:

ReferenceError: Error #1056: Cannot create property _title_cache on com.myproject.models.vo.BookVO

_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

Re: How can I use Flex to access foreign-keyed fields in Django?

by Joel Hooks :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

http://pastebin.com/m2ffcb77d

I use these methods to grab related models and whatnot.

ReferenceError: Error #1056: Cannot create property _title_cache on com.myproject.models.vo.BookVO

If you create a TitleVO object and then make a _title_cache:TitleVO property it will do some ORM bits. I personally hate this and wish it was either cleaner or more controllable (in an easy way).

-joel


On Mon, Jan 26, 2009 at 3:01 PM, Bryan Hughes <huuuze@...> wrote:
I need some help!  Please see the question I posted here:

http://stackoverflow.com/questions/481110/how-can-i-use-flex-to-access-foreign-keyed-fields-in-django

Does anyone know of a solution?  The one posted in the thread results in the following error:

ReferenceError: Error #1056: Cannot create property _title_cache on com.myproject.models.vo.BookVO

_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

Re: How can I use Flex to access foreign-keyed fields in Django?

by Joel Hooks :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

"I personally hate this and wish it was either cleaner or more controllable (in an easy way)."

I should add, but not so much that I get off my lazy butt and contribute to the project in a meaningful way. Thanks PyAmf dev team, you guys are awesome! I would like to turn off the caching globally though :>

On Mon, Jan 26, 2009 at 3:24 PM, Joel <imlowdown@...> wrote:
http://pastebin.com/m2ffcb77d

I use these methods to grab related models and whatnot.


ReferenceError: Error #1056: Cannot create property _title_cache on com.myproject.models.vo.BookVO

If you create a TitleVO object and then make a _title_cache:TitleVO property it will do some ORM bits. I personally hate this and wish it was either cleaner or more controllable (in an easy way).

-joel


On Mon, Jan 26, 2009 at 3:01 PM, Bryan Hughes <huuuze@...> wrote:
I need some help!  Please see the question I posted here:

http://stackoverflow.com/questions/481110/how-can-i-use-flex-to-access-foreign-keyed-fields-in-django

Does anyone know of a solution?  The one posted in the thread results in the following error:

ReferenceError: Error #1056: Cannot create property _title_cache on com.myproject.models.vo.BookVO

_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users




_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

Re: How can I use Flex to access foreign-keyed fields in Django?

by huuuze@gmail.com :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for the response.  From what I gather, adding the _cache fields to my VO seems a little dirty.

Does anyone know if DjangoAMF handles this dilemma in a cleaner manner?


On Mon, Jan 26, 2009 at 4:30 PM, Joel <imlowdown@...> wrote:
"I personally hate this and wish it was either cleaner or more controllable (in an easy way)."

I should add, but not so much that I get off my lazy butt and contribute to the project in a meaningful way. Thanks PyAmf dev team, you guys are awesome! I would like to turn off the caching globally though :>


On Mon, Jan 26, 2009 at 3:24 PM, Joel <imlowdown@...> wrote:
http://pastebin.com/m2ffcb77d

I use these methods to grab related models and whatnot.


ReferenceError: Error #1056: Cannot create property _title_cache on com.myproject.models.vo.BookVO

If you create a TitleVO object and then make a _title_cache:TitleVO property it will do some ORM bits. I personally hate this and wish it was either cleaner or more controllable (in an easy way).

-joel


On Mon, Jan 26, 2009 at 3:01 PM, Bryan Hughes <huuuze@...> wrote:
I need some help!  Please see the question I posted here:

http://stackoverflow.com/questions/481110/how-can-i-use-flex-to-access-foreign-keyed-fields-in-django

Does anyone know of a solution?  The one posted in the thread results in the following error:

ReferenceError: Error #1056: Cannot create property _title_cache on com.myproject.models.vo.BookVO

_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users




_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

Re: How can I use Flex to access foreign-keyed fields in Django?

by Joel Hooks :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

DjangoAMF doesn't handle it at all, you simply get the title_id:int back (as you do with PyAMF). It is also unsupported (for all practical purposes) and has some fairly crippling errors. Do not want.

Nick explained to me earlier this month how to override the Cache creation class to build your own custom cache. I would bet you could do this and attach the object cleanly to the returned object. I haven't tried this yet, but it is on my list of things to do. I will report back if I have success. Will probably test it out tonight.

On Mon, Jan 26, 2009 at 3:35 PM, Bryan Hughes <huuuze@...> wrote:
Thanks for the response.  From what I gather, adding the _cache fields to my VO seems a little dirty.

Does anyone know if DjangoAMF handles this dilemma in a cleaner manner?



On Mon, Jan 26, 2009 at 4:30 PM, Joel <imlowdown@...> wrote:
"I personally hate this and wish it was either cleaner or more controllable (in an easy way)."

I should add, but not so much that I get off my lazy butt and contribute to the project in a meaningful way. Thanks PyAmf dev team, you guys are awesome! I would like to turn off the caching globally though :>


On Mon, Jan 26, 2009 at 3:24 PM, Joel <imlowdown@...> wrote:
http://pastebin.com/m2ffcb77d

I use these methods to grab related models and whatnot.


ReferenceError: Error #1056: Cannot create property _title_cache on com.myproject.models.vo.BookVO

If you create a TitleVO object and then make a _title_cache:TitleVO property it will do some ORM bits. I personally hate this and wish it was either cleaner or more controllable (in an easy way).

-joel


On Mon, Jan 26, 2009 at 3:01 PM, Bryan Hughes <huuuze@...> wrote:
I need some help!  Please see the question I posted here:

http://stackoverflow.com/questions/481110/how-can-i-use-flex-to-access-foreign-keyed-fields-in-django

Does anyone know of a solution?  The one posted in the thread results in the following error:

ReferenceError: Error #1056: Cannot create property _title_cache on com.myproject.models.vo.BookVO

_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users




_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

Re: How can I use Flex to access foreign-keyed fields in Django?

by huuuze@gmail.com :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I don't mean to second guess, but are you certain DjangoAMF doesn't handle ForeignKeys in the manner I described?  I read through this post (http://sourceforge.jp/forum/forum.php?forum_id=10573&thread_id=16153) and the author implies this functionality has been made available in DjangoAMF 0.7.

Thank you again for your help.  Just getting frustrated with something I was hoping would be straightforward.


On Mon, Jan 26, 2009 at 4:44 PM, Joel <imlowdown@...> wrote:
DjangoAMF doesn't handle it at all, you simply get the title_id:int back (as you do with PyAMF). It is also unsupported (for all practical purposes) and has some fairly crippling errors. Do not want.

Nick explained to me earlier this month how to override the Cache creation class to build your own custom cache. I would bet you could do this and attach the object cleanly to the returned object. I haven't tried this yet, but it is on my list of things to do. I will report back if I have success. Will probably test it out tonight.


On Mon, Jan 26, 2009 at 3:35 PM, Bryan Hughes <huuuze@...> wrote:
Thanks for the response.  From what I gather, adding the _cache fields to my VO seems a little dirty.

Does anyone know if DjangoAMF handles this dilemma in a cleaner manner?



On Mon, Jan 26, 2009 at 4:30 PM, Joel <imlowdown@...> wrote:
"I personally hate this and wish it was either cleaner or more controllable (in an easy way)."

I should add, but not so much that I get off my lazy butt and contribute to the project in a meaningful way. Thanks PyAmf dev team, you guys are awesome! I would like to turn off the caching globally though :>


On Mon, Jan 26, 2009 at 3:24 PM, Joel <imlowdown@...> wrote:
http://pastebin.com/m2ffcb77d

I use these methods to grab related models and whatnot.


ReferenceError: Error #1056: Cannot create property _title_cache on com.myproject.models.vo.BookVO

If you create a TitleVO object and then make a _title_cache:TitleVO property it will do some ORM bits. I personally hate this and wish it was either cleaner or more controllable (in an easy way).

-joel


On Mon, Jan 26, 2009 at 3:01 PM, Bryan Hughes <huuuze@...> wrote:
I need some help!  Please see the question I posted here:

http://stackoverflow.com/questions/481110/how-can-i-use-flex-to-access-foreign-keyed-fields-in-django

Does anyone know of a solution?  The one posted in the thread results in the following error:

ReferenceError: Error #1056: Cannot create property _title_cache on com.myproject.models.vo.BookVO

_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users




_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

Re: How can I use Flex to access foreign-keyed fields in Django?

by Joel Hooks :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'd all but stopped following DjangoAmf with .5.5, so it is possible. Worth a test...

On Mon, Jan 26, 2009 at 4:11 PM, Bryan Hughes <huuuze@...> wrote:
I don't mean to second guess, but are you certain DjangoAMF doesn't handle ForeignKeys in the manner I described?  I read through this post (http://sourceforge.jp/forum/forum.php?forum_id=10573&thread_id=16153) and the author implies this functionality has been made available in DjangoAMF 0.7.

Thank you again for your help.  Just getting frustrated with something I was hoping would be straightforward.



On Mon, Jan 26, 2009 at 4:44 PM, Joel <imlowdown@...> wrote:
DjangoAMF doesn't handle it at all, you simply get the title_id:int back (as you do with PyAMF). It is also unsupported (for all practical purposes) and has some fairly crippling errors. Do not want.

Nick explained to me earlier this month how to override the Cache creation class to build your own custom cache. I would bet you could do this and attach the object cleanly to the returned object. I haven't tried this yet, but it is on my list of things to do. I will report back if I have success. Will probably test it out tonight.


On Mon, Jan 26, 2009 at 3:35 PM, Bryan Hughes <huuuze@...> wrote:
Thanks for the response.  From what I gather, adding the _cache fields to my VO seems a little dirty.

Does anyone know if DjangoAMF handles this dilemma in a cleaner manner?



On Mon, Jan 26, 2009 at 4:30 PM, Joel <imlowdown@...> wrote:
"I personally hate this and wish it was either cleaner or more controllable (in an easy way)."

I should add, but not so much that I get off my lazy butt and contribute to the project in a meaningful way. Thanks PyAmf dev team, you guys are awesome! I would like to turn off the caching globally though :>


On Mon, Jan 26, 2009 at 3:24 PM, Joel <imlowdown@...> wrote:
http://pastebin.com/m2ffcb77d

I use these methods to grab related models and whatnot.


ReferenceError: Error #1056: Cannot create property _title_cache on com.myproject.models.vo.BookVO

If you create a TitleVO object and then make a _title_cache:TitleVO property it will do some ORM bits. I personally hate this and wish it was either cleaner or more controllable (in an easy way).

-joel


On Mon, Jan 26, 2009 at 3:01 PM, Bryan Hughes <huuuze@...> wrote:
I need some help!  Please see the question I posted here:

http://stackoverflow.com/questions/481110/how-can-i-use-flex-to-access-foreign-keyed-fields-in-django

Does anyone know of a solution?  The one posted in the thread results in the following error:

ReferenceError: Error #1056: Cannot create property _title_cache on com.myproject.models.vo.BookVO

_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users




_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

Re: How can I use Flex to access foreign-keyed fields in Django?

by Nick Joyce :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Bryan,

Welcome!

I hadn't realised that foreign key relationships were not being  
followed on encoding.

I have spent some time putting together an adapter that support django  
foreign keys out of the box without you (the user) having to do  
anything except provide a `select_related`.

An example:

# models

class Author(models.Model):
     name = models.CharField(max_length=100)

class Book(models.Model):
     title = models.CharField(max_length=50)
     author = models.ForeignKey(Author)

# views
import pyamf
from pyamf.remoting.gateway.django import DjangoGateway

from myproject.myapp.models import Book

def only_books():
     return Book.objects.all()

def books_and_authors():
     return Book.objects.select_related().all()

gateway = DjangoGateway({
     'only_books': only_books,
     'books_and_authors': books_and_authors
})

The `only_books` method will return a list of book objects with no  
author objects (as foreign keys are lazily loaded) whereas  
`books_and_authors` will return books with author objects attached to  
them. <-- Hope that all makes sense :)

If you want this behaviour then apply the diff attached to your pyamf  
tree. I have (lightly) tested for encoding but not decoding so use  
with caution.

If the patch seems reasonable we can get some tests for it and make it  
part of 0.4.1.

Joel, this should save you some time investigating the cache issue you  
were having - hope it goes some way to solving your problem.

Cheers,

Nick






On 26 Jan 2009, at 22:11, Bryan Hughes wrote:

> I don't mean to second guess, but are you certain DjangoAMF doesn't  
> handle ForeignKeys in the manner I described?  I read through this  
> post (http://sourceforge.jp/forum/forum.php?forum_id=10573&thread_id=16153 
> ) and the author implies this functionality has been made available  
> in DjangoAMF 0.7.
>
> Thank you again for your help.  Just getting frustrated with  
> something I was hoping would be straightforward.
>
>
> On Mon, Jan 26, 2009 at 4:44 PM, Joel <imlowdown@...> wrote:
> DjangoAMF doesn't handle it at all, you simply get the title_id:int  
> back (as you do with PyAMF). It is also unsupported (for all  
> practical purposes) and has some fairly crippling errors. Do not want.
>
> Nick explained to me earlier this month how to override the Cache  
> creation class to build your own custom cache. I would bet you could  
> do this and attach the object cleanly to the returned object. I  
> haven't tried this yet, but it is on my list of things to do. I will  
> report back if I have success. Will probably test it out tonight.
>
>
> On Mon, Jan 26, 2009 at 3:35 PM, Bryan Hughes <huuuze@...>  
> wrote:
> Thanks for the response.  From what I gather, adding the _cache  
> fields to my VO seems a little dirty.
>
> Does anyone know if DjangoAMF handles this dilemma in a cleaner  
> manner?
>
>
>
> On Mon, Jan 26, 2009 at 4:30 PM, Joel <imlowdown@...> wrote:
> "I personally hate this and wish it was either cleaner or more  
> controllable (in an easy way)."
>
> I should add, but not so much that I get off my lazy butt and  
> contribute to the project in a meaningful way. Thanks PyAmf dev  
> team, you guys are awesome! I would like to turn off the caching  
> globally though :>
>
>
> On Mon, Jan 26, 2009 at 3:24 PM, Joel <imlowdown@...> wrote:
> http://pastebin.com/m2ffcb77d
>
> I use these methods to grab related models and whatnot.
>
>
> ReferenceError: Error #1056: Cannot create property _title_cache on  
> com.myproject.models.vo.BookVO
>
> If you create a TitleVO object and then make a _title_cache:TitleVO  
> property it will do some ORM bits. I personally hate this and wish  
> it was either cleaner or more controllable (in an easy way).
>
> -joel
>
>
> On Mon, Jan 26, 2009 at 3:01 PM, Bryan Hughes <huuuze@...>  
> wrote:
> I need some help!  Please see the question I posted here:
>
> http://stackoverflow.com/questions/481110/how-can-i-use-flex-to-access-foreign-keyed-fields-in-django
>
> Does anyone know of a solution?  The one posted in the thread  
> results in the following error:
>
> ReferenceError: Error #1056: Cannot create property _title_cache on  
> com.myproject.models.vo.BookVO
>
> _______________________________________________
> PyAMF users mailing list - users@...
> http://lists.pyamf.org/mailman/listinfo/users
>
>
>
>
> _______________________________________________
> PyAMF users mailing list - users@...
> http://lists.pyamf.org/mailman/listinfo/users
>
>
>
> _______________________________________________
> PyAMF users mailing list - users@...
> http://lists.pyamf.org/mailman/listinfo/users
>
>
>
> _______________________________________________
> PyAMF users mailing list - users@...
> http://lists.pyamf.org/mailman/listinfo/users
>
>
> _______________________________________________
> PyAMF users mailing list - users@...
> http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

django-foreignkey.diff (1K) Download Attachment

Re: How can I use Flex to access foreign-keyed fields in Django?

by Joel Hooks :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Awesome Nick. That is great.

Cheers,

Joel

On Mon, Jan 26, 2009 at 5:57 PM, Nick Joyce <nick@...> wrote:
Hi Bryan,

Welcome!

I hadn't realised that foreign key relationships were not being followed on encoding.

I have spent some time putting together an adapter that support django foreign keys out of the box without you (the user) having to do anything except provide a `select_related`.

An example:

# models

class Author(models.Model):
   name = models.CharField(max_length=100)

class Book(models.Model):
   title = models.CharField(max_length=50)
   author = models.ForeignKey(Author)

# views
import pyamf
from pyamf.remoting.gateway.django import DjangoGateway

from myproject.myapp.models import Book

def only_books():
   return Book.objects.all()

def books_and_authors():
   return Book.objects.select_related().all()

gateway = DjangoGateway({
   'only_books': only_books,
   'books_and_authors': books_and_authors
})

The `only_books` method will return a list of book objects with no author objects (as foreign keys are lazily loaded) whereas `books_and_authors` will return books with author objects attached to them. <-- Hope that all makes sense :)

If you want this behaviour then apply the diff attached to your pyamf tree. I have (lightly) tested for encoding but not decoding so use with caution.

If the patch seems reasonable we can get some tests for it and make it part of 0.4.1.

Joel, this should save you some time investigating the cache issue you were having - hope it goes some way to solving your problem.

Cheers,

Nick





On 26 Jan 2009, at 22:11, Bryan Hughes wrote:

I don't mean to second guess, but are you certain DjangoAMF doesn't handle ForeignKeys in the manner I described?  I read through this post (http://sourceforge.jp/forum/forum.php?forum_id=10573&thread_id=16153) and the author implies this functionality has been made available in DjangoAMF 0.7.

Thank you again for your help.  Just getting frustrated with something I was hoping would be straightforward.


On Mon, Jan 26, 2009 at 4:44 PM, Joel <imlowdown@...> wrote:
DjangoAMF doesn't handle it at all, you simply get the title_id:int back (as you do with PyAMF). It is also unsupported (for all practical purposes) and has some fairly crippling errors. Do not want.

Nick explained to me earlier this month how to override the Cache creation class to build your own custom cache. I would bet you could do this and attach the object cleanly to the returned object. I haven't tried this yet, but it is on my list of things to do. I will report back if I have success. Will probably test it out tonight.


On Mon, Jan 26, 2009 at 3:35 PM, Bryan Hughes <huuuze@...> wrote:
Thanks for the response.  From what I gather, adding the _cache fields to my VO seems a little dirty.

Does anyone know if DjangoAMF handles this dilemma in a cleaner manner?



On Mon, Jan 26, 2009 at 4:30 PM, Joel <imlowdown@...> wrote:
"I personally hate this and wish it was either cleaner or more controllable (in an easy way)."

I should add, but not so much that I get off my lazy butt and contribute to the project in a meaningful way. Thanks PyAmf dev team, you guys are awesome! I would like to turn off the caching globally though :>


On Mon, Jan 26, 2009 at 3:24 PM, Joel <imlowdown@...> wrote:
http://pastebin.com/m2ffcb77d

I use these methods to grab related models and whatnot.


ReferenceError: Error #1056: Cannot create property _title_cache on com.myproject.models.vo.BookVO

If you create a TitleVO object and then make a _title_cache:TitleVO property it will do some ORM bits. I personally hate this and wish it was either cleaner or more controllable (in an easy way).

-joel


On Mon, Jan 26, 2009 at 3:01 PM, Bryan Hughes <huuuze@...> wrote:
I need some help!  Please see the question I posted here:

http://stackoverflow.com/questions/481110/how-can-i-use-flex-to-access-foreign-keyed-fields-in-django

Does anyone know of a solution?  The one posted in the thread results in the following error:

ReferenceError: Error #1056: Cannot create property _title_cache on com.myproject.models.vo.BookVO

_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users




_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users


_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users


_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

Re: How can I use Flex to access foreign-keyed fields in Django?

by huuuze@gmail.com :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Nick...thank you for the quick response.

I've implemented your patch, but I'm still coming up empty.  When I view my BookVO, the "author" attribute is null (despite using "select_related()").  However, I will note that I can access the author name if I call "_author_cache.name".  Not sure if that's how you intended it to work.

bryan

On Mon, Jan 26, 2009 at 6:57 PM, Nick Joyce <nick@...> wrote:
Hi Bryan,

Welcome!

I hadn't realised that foreign key relationships were not being followed on encoding.

I have spent some time putting together an adapter that support django foreign keys out of the box without you (the user) having to do anything except provide a `select_related`.

An example:

# models

class Author(models.Model):
   name = models.CharField(max_length=100)

class Book(models.Model):
   title = models.CharField(max_length=50)
   author = models.ForeignKey(Author)

# views
import pyamf
from pyamf.remoting.gateway.django import DjangoGateway

from myproject.myapp.models import Book

def only_books():
   return Book.objects.all()

def books_and_authors():
   return Book.objects.select_related().all()

gateway = DjangoGateway({
   'only_books': only_books,
   'books_and_authors': books_and_authors
})

The `only_books` method will return a list of book objects with no author objects (as foreign keys are lazily loaded) whereas `books_and_authors` will return books with author objects attached to them. <-- Hope that all makes sense :)

If you want this behaviour then apply the diff attached to your pyamf tree. I have (lightly) tested for encoding but not decoding so use with caution.

If the patch seems reasonable we can get some tests for it and make it part of 0.4.1.

Joel, this should save you some time investigating the cache issue you were having - hope it goes some way to solving your problem.

Cheers,

Nick





On 26 Jan 2009, at 22:11, Bryan Hughes wrote:

I don't mean to second guess, but are you certain DjangoAMF doesn't handle ForeignKeys in the manner I described?  I read through this post (http://sourceforge.jp/forum/forum.php?forum_id=10573&thread_id=16153) and the author implies this functionality has been made available in DjangoAMF 0.7.

Thank you again for your help.  Just getting frustrated with something I was hoping would be straightforward.


On Mon, Jan 26, 2009 at 4:44 PM, Joel <imlowdown@...> wrote:
DjangoAMF doesn't handle it at all, you simply get the title_id:int back (as you do with PyAMF). It is also unsupported (for all practical purposes) and has some fairly crippling errors. Do not want.

Nick explained to me earlier this month how to override the Cache creation class to build your own custom cache. I would bet you could do this and attach the object cleanly to the returned object. I haven't tried this yet, but it is on my list of things to do. I will report back if I have success. Will probably test it out tonight.


On Mon, Jan 26, 2009 at 3:35 PM, Bryan Hughes <huuuze@...> wrote:
Thanks for the response.  From what I gather, adding the _cache fields to my VO seems a little dirty.

Does anyone know if DjangoAMF handles this dilemma in a cleaner manner?



On Mon, Jan 26, 2009 at 4:30 PM, Joel <imlowdown@...> wrote:
"I personally hate this and wish it was either cleaner or more controllable (in an easy way)."

I should add, but not so much that I get off my lazy butt and contribute to the project in a meaningful way. Thanks PyAmf dev team, you guys are awesome! I would like to turn off the caching globally though :>


On Mon, Jan 26, 2009 at 3:24 PM, Joel <imlowdown@...> wrote:
http://pastebin.com/m2ffcb77d

I use these methods to grab related models and whatnot.


ReferenceError: Error #1056: Cannot create property _title_cache on com.myproject.models.vo.BookVO

If you create a TitleVO object and then make a _title_cache:TitleVO property it will do some ORM bits. I personally hate this and wish it was either cleaner or more controllable (in an easy way).

-joel


On Mon, Jan 26, 2009 at 3:01 PM, Bryan Hughes <huuuze@...> wrote:
I need some help!  Please see the question I posted here:

http://stackoverflow.com/questions/481110/how-can-i-use-flex-to-access-foreign-keyed-fields-in-django

Does anyone know of a solution?  The one posted in the thread results in the following error:

ReferenceError: Error #1056: Cannot create property _title_cache on com.myproject.models.vo.BookVO

_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users




_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users


_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users


_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

Re: How can I use Flex to access foreign-keyed fields in Django?

by huuuze@gmail.com :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Nick...I stand corrected.  I failed to apply the patch properly when I wrote that last email.  It works perfectly!  Thank you!


On Tue, Jan 27, 2009 at 12:21 PM, Bryan Hughes <huuuze@...> wrote:
Nick...thank you for the quick response.

I've implemented your patch, but I'm still coming up empty.  When I view my BookVO, the "author" attribute is null (despite using "select_related()").  However, I will note that I can access the author name if I call "_author_cache.name".  Not sure if that's how you intended it to work.

bryan

On Mon, Jan 26, 2009 at 6:57 PM, Nick Joyce <nick@...> wrote:
Hi Bryan,

Welcome!

I hadn't realised that foreign key relationships were not being followed on encoding.

I have spent some time putting together an adapter that support django foreign keys out of the box without you (the user) having to do anything except provide a `select_related`.

An example:

# models

class Author(models.Model):
   name = models.CharField(max_length=100)

class Book(models.Model):
   title = models.CharField(max_length=50)
   author = models.ForeignKey(Author)

# views
import pyamf
from pyamf.remoting.gateway.django import DjangoGateway

from myproject.myapp.models import Book

def only_books():
   return Book.objects.all()

def books_and_authors():
   return Book.objects.select_related().all()

gateway = DjangoGateway({
   'only_books': only_books,
   'books_and_authors': books_and_authors
})

The `only_books` method will return a list of book objects with no author objects (as foreign keys are lazily loaded) whereas `books_and_authors` will return books with author objects attached to them. <-- Hope that all makes sense :)

If you want this behaviour then apply the diff attached to your pyamf tree. I have (lightly) tested for encoding but not decoding so use with caution.

If the patch seems reasonable we can get some tests for it and make it part of 0.4.1.

Joel, this should save you some time investigating the cache issue you were having - hope it goes some way to solving your problem.

Cheers,

Nick





On 26 Jan 2009, at 22:11, Bryan Hughes wrote:

I don't mean to second guess, but are you certain DjangoAMF doesn't handle ForeignKeys in the manner I described?  I read through this post (http://sourceforge.jp/forum/forum.php?forum_id=10573&thread_id=16153) and the author implies this functionality has been made available in DjangoAMF 0.7.

Thank you again for your help.  Just getting frustrated with something I was hoping would be straightforward.


On Mon, Jan 26, 2009 at 4:44 PM, Joel <imlowdown@...> wrote:
DjangoAMF doesn't handle it at all, you simply get the title_id:int back (as you do with PyAMF). It is also unsupported (for all practical purposes) and has some fairly crippling errors. Do not want.

Nick explained to me earlier this month how to override the Cache creation class to build your own custom cache. I would bet you could do this and attach the object cleanly to the returned object. I haven't tried this yet, but it is on my list of things to do. I will report back if I have success. Will probably test it out tonight.


On Mon, Jan 26, 2009 at 3:35 PM, Bryan Hughes <huuuze@...> wrote:
Thanks for the response.  From what I gather, adding the _cache fields to my VO seems a little dirty.

Does anyone know if DjangoAMF handles this dilemma in a cleaner manner?



On Mon, Jan 26, 2009 at 4:30 PM, Joel <imlowdown@...> wrote:
"I personally hate this and wish it was either cleaner or more controllable (in an easy way)."

I should add, but not so much that I get off my lazy butt and contribute to the project in a meaningful way. Thanks PyAmf dev team, you guys are awesome! I would like to turn off the caching globally though :>


On Mon, Jan 26, 2009 at 3:24 PM, Joel <imlowdown@...> wrote:
http://pastebin.com/m2ffcb77d

I use these methods to grab related models and whatnot.


ReferenceError: Error #1056: Cannot create property _title_cache on com.myproject.models.vo.BookVO

If you create a TitleVO object and then make a _title_cache:TitleVO property it will do some ORM bits. I personally hate this and wish it was either cleaner or more controllable (in an easy way).

-joel


On Mon, Jan 26, 2009 at 3:01 PM, Bryan Hughes <huuuze@...> wrote:
I need some help!  Please see the question I posted here:

http://stackoverflow.com/questions/481110/how-can-i-use-flex-to-access-foreign-keyed-fields-in-django

Does anyone know of a solution?  The one posted in the thread results in the following error:

ReferenceError: Error #1056: Cannot create property _title_cache on com.myproject.models.vo.BookVO

_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users




_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users


_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users


_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users




_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

Re: How can I use Flex to access foreign-keyed fields in Django?

by lists-144 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Looks like http://pyamf.org/ticket/456 was opened for this issue.

Cheers,

Thijs

On 27 Jan 2009, at 18:11, Bryan Hughes wrote:

Nick...I stand corrected.  I failed to apply the patch properly when I wrote that last email.  It works perfectly!  Thank you!


On Tue, Jan 27, 2009 at 12:21 PM, Bryan Hughes <huuuze@...> wrote:
Nick...thank you for the quick response.

I've implemented your patch, but I'm still coming up empty.  When I view my BookVO, the "author" attribute is null (despite using "select_related()").  However, I will note that I can access the author name if I call "_author_cache.name".  Not sure if that's how you intended it to work.

bryan

On Mon, Jan 26, 2009 at 6:57 PM, Nick Joyce <nick@...> wrote:
Hi Bryan,

Welcome!

I hadn't realised that foreign key relationships were not being followed on encoding.

I have spent some time putting together an adapter that support django foreign keys out of the box without you (the user) having to do anything except provide a `select_related`.

An example:

# models

class Author(models.Model):
   name = models.CharField(max_length=100)

class Book(models.Model):
   title = models.CharField(max_length=50)
   author = models.ForeignKey(Author)

# views
import pyamf
from pyamf.remoting.gateway.django import DjangoGateway

from myproject.myapp.models import Book

def only_books():
   return Book.objects.all()

def books_and_authors():
   return Book.objects.select_related().all()

gateway = DjangoGateway({
   'only_books': only_books,
   'books_and_authors': books_and_authors
})

The `only_books` method will return a list of book objects with no author objects (as foreign keys are lazily loaded) whereas `books_and_authors` will return books with author objects attached to them. <-- Hope that all makes sense :)

If you want this behaviour then apply the diff attached to your pyamf tree. I have (lightly) tested for encoding but not decoding so use with caution.

If the patch seems reasonable we can get some tests for it and make it part of 0.4.1.

Joel, this should save you some time investigating the cache issue you were having - hope it goes some way to solving your problem.

Cheers,

Nick





On 26 Jan 2009, at 22:11, Bryan Hughes wrote:

I don't mean to second guess, but are you certain DjangoAMF doesn't handle ForeignKeys in the manner I described?  I read through this post (http://sourceforge.jp/forum/forum.php?forum_id=10573&thread_id=16153) and the author implies this functionality has been made available in DjangoAMF 0.7.

Thank you again for your help.  Just getting frustrated with something I was hoping would be straightforward.


On Mon, Jan 26, 2009 at 4:44 PM, Joel <imlowdown@...> wrote:
DjangoAMF doesn't handle it at all, you simply get the title_id:int back (as you do with PyAMF). It is also unsupported (for all practical purposes) and has some fairly crippling errors. Do not want.

Nick explained to me earlier this month how to override the Cache creation class to build your own custom cache. I would bet you could do this and attach the object cleanly to the returned object. I haven't tried this yet, but it is on my list of things to do. I will report back if I have success. Will probably test it out tonight.


On Mon, Jan 26, 2009 at 3:35 PM, Bryan Hughes <huuuze@...> wrote:
Thanks for the response.  From what I gather, adding the _cache fields to my VO seems a little dirty.

Does anyone know if DjangoAMF handles this dilemma in a cleaner manner?



On Mon, Jan 26, 2009 at 4:30 PM, Joel <imlowdown@...> wrote:
"I personally hate this and wish it was either cleaner or more controllable (in an easy way)."

I should add, but not so much that I get off my lazy butt and contribute to the project in a meaningful way. Thanks PyAmf dev team, you guys are awesome! I would like to turn off the caching globally though :>


On Mon, Jan 26, 2009 at 3:24 PM, Joel <imlowdown@...> wrote:
http://pastebin.com/m2ffcb77d

I use these methods to grab related models and whatnot.


ReferenceError: Error #1056: Cannot create property _title_cache on com.myproject.models.vo.BookVO

If you create a TitleVO object and then make a _title_cache:TitleVO property it will do some ORM bits. I personally hate this and wish it was either cleaner or more controllable (in an easy way).

-joel


On Mon, Jan 26, 2009 at 3:01 PM, Bryan Hughes <huuuze@...> wrote:
I need some help!  Please see the question I posted here:

http://stackoverflow.com/questions/481110/how-can-i-use-flex-to-access-foreign-keyed-fields-in-django

Does anyone know of a solution?  The one posted in the thread results in the following error:

ReferenceError: Error #1056: Cannot create property _title_cache on com.myproject.models.vo.BookVO

_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users




_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users


_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users


_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

PGP.sig (201 bytes) Download Attachment

Re: How can I use Flex to access foreign-keyed fields in Django?

by Joel Hooks-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Nick,

This failed on the following model with a 'cannot encode' 500 error:

def get_studio_watermark(instance, filename):
    return 'watermarks/%s/%s' % (instance.id, filename)

class StudioWatermark(models.Model):
    studio              = models.ForeignKey(Studio, related_name="watermark", unique=True)
    image               = models.ImageField(upload_to=get_studio_watermark,blank=True,null=True)
    text                = models.CharField(max_length=64)
    def __unicode__(self):
        return '%s Watermark' % (self.studio.name)

That said, it worked on my other models as expected (I don't know how to test what the problem might be), but what I want to do is completely eliminate the cache altogether. I have some models that are a bit recursive, and it jumps my transfer of objects from a couple of hundred kB to a whopping 30mb of redundant data. obviously that is less than optimum.

Can I somehow adapt what you have done to completely strip the cache feature altogether?

Cheers,

Joel

On Mon, Jan 26, 2009 at 5:57 PM, Nick Joyce <nick@...> wrote:
Hi Bryan,

Welcome!

I hadn't realised that foreign key relationships were not being followed on encoding.

I have spent some time putting together an adapter that support django foreign keys out of the box without you (the user) having to do anything except provide a `select_related`.

An example:

# models

class Author(models.Model):
   name = models.CharField(max_length=100)

class Book(models.Model):
   title = models.CharField(max_length=50)
   author = models.ForeignKey(Author)

# views
import pyamf
from pyamf.remoting.gateway.django import DjangoGateway

from myproject.myapp.models import Book

def only_books():
   return Book.objects.all()

def books_and_authors():
   return Book.objects.select_related().all()

gateway = DjangoGateway({
   'only_books': only_books,
   'books_and_authors': books_and_authors
})

The `only_books` method will return a list of book objects with no author objects (as foreign keys are lazily loaded) whereas `books_and_authors` will return books with author objects attached to them. <-- Hope that all makes sense :)

If you want this behaviour then apply the diff attached to your pyamf tree. I have (lightly) tested for encoding but not decoding so use with caution.

If the patch seems reasonable we can get some tests for it and make it part of 0.4.1.

Joel, this should save you some time investigating the cache issue you were having - hope it goes some way to solving your problem.

Cheers,

Nick





On 26 Jan 2009, at 22:11, Bryan Hughes wrote:

I don't mean to second guess, but are you certain DjangoAMF doesn't handle ForeignKeys in the manner I described?  I read through this post (http://sourceforge.jp/forum/forum.php?forum_id=10573&thread_id=16153) and the author implies this functionality has been made available in DjangoAMF 0.7.

Thank you again for your help.  Just getting frustrated with something I was hoping would be straightforward.


On Mon, Jan 26, 2009 at 4:44 PM, Joel <imlowdown@...> wrote:
DjangoAMF doesn't handle it at all, you simply get the title_id:int back (as you do with PyAMF). It is also unsupported (for all practical purposes) and has some fairly crippling errors. Do not want.

Nick explained to me earlier this month how to override the Cache creation class to build your own custom cache. I would bet you could do this and attach the object cleanly to the returned object. I haven't tried this yet, but it is on my list of things to do. I will report back if I have success. Will probably test it out tonight.


On Mon, Jan 26, 2009 at 3:35 PM, Bryan Hughes <huuuze@...> wrote:
Thanks for the response.  From what I gather, adding the _cache fields to my VO seems a little dirty.

Does anyone know if DjangoAMF handles this dilemma in a cleaner manner?



On Mon, Jan 26, 2009 at 4:30 PM, Joel <imlowdown@...> wrote:
"I personally hate this and wish it was either cleaner or more controllable (in an easy way)."

I should add, but not so much that I get off my lazy butt and contribute to the project in a meaningful way. Thanks PyAmf dev team, you guys are awesome! I would like to turn off the caching globally though :>


On Mon, Jan 26, 2009 at 3:24 PM, Joel <imlowdown@...> wrote:
http://pastebin.com/m2ffcb77d

I use these methods to grab related models and whatnot.


ReferenceError: Error #1056: Cannot create property _title_cache on com.myproject.models.vo.BookVO

If you create a TitleVO object and then make a _title_cache:TitleVO property it will do some ORM bits. I personally hate this and wish it was either cleaner or more controllable (in an easy way).

-joel


On Mon, Jan 26, 2009 at 3:01 PM, Bryan Hughes <huuuze@...> wrote:
I need some help!  Please see the question I posted here:

http://stackoverflow.com/questions/481110/how-can-i-use-flex-to-access-foreign-keyed-fields-in-django

Does anyone know of a solution?  The one posted in the thread results in the following error:

ReferenceError: Error #1056: Cannot create property _title_cache on com.myproject.models.vo.BookVO

_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users




_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users


_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users


_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

Re: How can I use Flex to access foreign-keyed fields in Django?

by Nick Joyce :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hmm, that is definitely not the desired behaviour.

I have attached a patch that strips out all django ForeignKey fields,  
it replaces the previous patch I supplied.

You can control the attributes that PyAMF encodes by supplying the  
attribute list that you want to encode through the register_class  
function. An example:

class Author(models.Model):
     name = models.StringField(max_length=255)

class Book(models.Model):
     name = models.StringField(max_length=255)
     do_not_include_this_property = models.StringField(max_length=10)
     author = models.ForeignKey(Author)

pyamf.register_class(Author, 'foo.bar.Author')
pyamf.register_class(Book, 'foo.bar.Book', attrs=['name', 'author'])

If you know your AMF, then attrs actually supplies a list of static  
attributes for the class (specific to AMF3 only) so in supplying that  
list, you guarantee that each instance of that class encoded/decoded  
has that list of attributes, which in Django's ORM is not a problem.

I am currently toying with the idea of an exclude_attr option so that  
you don't have to repeat yourself too much.

Can you send me a dump of the request/response that causes that 500?  
Is there a traceback?

Thanks!

Nick

On 8 Feb 2009, at 19:00, joelhooks wrote:

> Nick,
>
> This failed on the following model with a 'cannot encode' 500 error:
>
> def get_studio_watermark(instance, filename):
>     return 'watermarks/%s/%s' % (instance.id, filename)
>
> class StudioWatermark(models.Model):
>     studio              = models.ForeignKey(Studio,  
> related_name="watermark", unique=True)
>     image               =  
> models.ImageField(upload_to=get_studio_watermark,blank=True,null=True)
>     text                = models.CharField(max_length=64)
>     def __unicode__(self):
>         return '%s Watermark' % (self.studio.name)
>
> That said, it worked on my other models as expected (I don't know  
> how to test what the problem might be), but what I want to do is  
> completely eliminate the cache altogether. I have some models that  
> are a bit recursive, and it jumps my transfer of objects from a  
> couple of hundred kB to a whopping 30mb of redundant data. obviously  
> that is less than optimum.
>
> Can I somehow adapt what you have done to completely strip the cache  
> feature altogether?
>
> Cheers,
>
> Joel
>
> On Mon, Jan 26, 2009 at 5:57 PM, Nick Joyce <nick@...>  
> wrote:
> Hi Bryan,
>
> Welcome!
>
> I hadn't realised that foreign key relationships were not being  
> followed on encoding.
>
> I have spent some time putting together an adapter that support  
> django foreign keys out of the box without you (the user) having to  
> do anything except provide a `select_related`.
>
> An example:
>
> # models
>
> class Author(models.Model):
>    name = models.CharField(max_length=100)
>
> class Book(models.Model):
>    title = models.CharField(max_length=50)
>    author = models.ForeignKey(Author)
>
> # views
> import pyamf
> from pyamf.remoting.gateway.django import DjangoGateway
>
> from myproject.myapp.models import Book
>
> def only_books():
>    return Book.objects.all()
>
> def books_and_authors():
>    return Book.objects.select_related().all()
>
> gateway = DjangoGateway({
>    'only_books': only_books,
>    'books_and_authors': books_and_authors
> })
>
> The `only_books` method will return a list of book objects with no  
> author objects (as foreign keys are lazily loaded) whereas  
> `books_and_authors` will return books with author objects attached  
> to them. <-- Hope that all makes sense :)
>
> If you want this behaviour then apply the diff attached to your  
> pyamf tree. I have (lightly) tested for encoding but not decoding so  
> use with caution.
>
> If the patch seems reasonable we can get some tests for it and make  
> it part of 0.4.1.
>
> Joel, this should save you some time investigating the cache issue  
> you were having - hope it goes some way to solving your problem.
>
> Cheers,
>
> Nick
>
>
>
>
>
> On 26 Jan 2009, at 22:11, Bryan Hughes wrote:
>
> I don't mean to second guess, but are you certain DjangoAMF doesn't  
> handle ForeignKeys in the manner I described?  I read through this  
> post (http://sourceforge.jp/forum/forum.php?forum_id=10573&thread_id=16153 
> ) and the author implies this functionality has been made available  
> in DjangoAMF 0.7.
>
> Thank you again for your help.  Just getting frustrated with  
> something I was hoping would be straightforward.
>
>
> On Mon, Jan 26, 2009 at 4:44 PM, Joel <imlowdown@...> wrote:
> DjangoAMF doesn't handle it at all, you simply get the title_id:int  
> back (as you do with PyAMF). It is also unsupported (for all  
> practical purposes) and has some fairly crippling errors. Do not want.
>
> Nick explained to me earlier this month how to override the Cache  
> creation class to build your own custom cache. I would bet you could  
> do this and attach the object cleanly to the returned object. I  
> haven't tried this yet, but it is on my list of things to do. I will  
> report back if I have success. Will probably test it out tonight.
>
>
> On Mon, Jan 26, 2009 at 3:35 PM, Bryan Hughes <huuuze@...>  
> wrote:
> Thanks for the response.  From what I gather, adding the _cache  
> fields to my VO seems a little dirty.
>
> Does anyone know if DjangoAMF handles this dilemma in a cleaner  
> manner?
>
>
>
> On Mon, Jan 26, 2009 at 4:30 PM, Joel <imlowdown@...> wrote:
> "I personally hate this and wish it was either cleaner or more  
> controllable (in an easy way)."
>
> I should add, but not so much that I get off my lazy butt and  
> contribute to the project in a meaningful way. Thanks PyAmf dev  
> team, you guys are awesome! I would like to turn off the caching  
> globally though :>
>
>
> On Mon, Jan 26, 2009 at 3:24 PM, Joel <imlowdown@...> wrote:
> http://pastebin.com/m2ffcb77d
>
> I use these methods to grab related models and whatnot.
>
>
> ReferenceError: Error #1056: Cannot create property _title_cache on  
> com.myproject.models.vo.BookVO
>
> If you create a TitleVO object and then make a _title_cache:TitleVO  
> property it will do some ORM bits. I personally hate this and wish  
> it was either cleaner or more controllable (in an easy way).
>
> -joel
>
>
> On Mon, Jan 26, 2009 at 3:01 PM, Bryan Hughes <huuuze@...>  
> wrote:
> I need some help!  Please see the question I posted here:
>
> http://stackoverflow.com/questions/481110/how-can-i-use-flex-to-access-foreign-keyed-fields-in-django
>
> Does anyone know of a solution?  The one posted in the thread  
> results in the following error:
>
> ReferenceError: Error #1056: Cannot create property _title_cache on  
> com.myproject.models.vo.BookVO
>
> _______________________________________________
> PyAMF users mailing list - users@...
> http://lists.pyamf.org/mailman/listinfo/users
>
>
>
>
> _______________________________________________
> PyAMF users mailing list - users@...
> http://lists.pyamf.org/mailman/listinfo/users
>
>
>
> _______________________________________________
> PyAMF users mailing list - users@...
> http://lists.pyamf.org/mailman/listinfo/users
>
>
>
> _______________________________________________
> PyAMF users mailing list - users@...
> http://lists.pyamf.org/mailman/listinfo/users
>
>
> _______________________________________________
> PyAMF users mailing list - users@...
> http://lists.pyamf.org/mailman/listinfo/users
>
>
> _______________________________________________
> PyAMF users mailing list - users@...
> http://lists.pyamf.org/mailman/listinfo/users
>
>
> _______________________________________________
> PyAMF users mailing list - users@...
> http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

Re: How can I use Flex to access foreign-keyed fields in Django?

by Nick Joyce :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

And now for my next trick .. the attached file.






On 8 Feb 2009, at 19:00, joelhooks wrote:

> Nick,
>
> This failed on the following model with a 'cannot encode' 500 error:
>
> def get_studio_watermark(instance, filename):
>     return 'watermarks/%s/%s' % (instance.id, filename)
>
> class StudioWatermark(models.Model):
>     studio              = models.ForeignKey(Studio,  
> related_name="watermark", unique=True)
>     image               =  
> models.ImageField(upload_to=get_studio_watermark,blank=True,null=True)
>     text                = models.CharField(max_length=64)
>     def __unicode__(self):
>         return '%s Watermark' % (self.studio.name)
>
> That said, it worked on my other models as expected (I don't know  
> how to test what the problem might be), but what I want to do is  
> completely eliminate the cache altogether. I have some models that  
> are a bit recursive, and it jumps my transfer of objects from a  
> couple of hundred kB to a whopping 30mb of redundant data. obviously  
> that is less than optimum.
>
> Can I somehow adapt what you have done to completely strip the cache  
> feature altogether?
>
> Cheers,
>
> Joel
>
> On Mon, Jan 26, 2009 at 5:57 PM, Nick Joyce <nick@...>  
> wrote:
> Hi Bryan,
>
> Welcome!
>
> I hadn't realised that foreign key relationships were not being  
> followed on encoding.
>
> I have spent some time putting together an adapter that support  
> django foreign keys out of the box without you (the user) having to  
> do anything except provide a `select_related`.
>
> An example:
>
> # models
>
> class Author(models.Model):
>    name = models.CharField(max_length=100)
>
> class Book(models.Model):
>    title = models.CharField(max_length=50)
>    author = models.ForeignKey(Author)
>
> # views
> import pyamf
> from pyamf.remoting.gateway.django import DjangoGateway
>
> from myproject.myapp.models import Book
>
> def only_books():
>    return Book.objects.all()
>
> def books_and_authors():
>    return Book.objects.select_related().all()
>
> gateway = DjangoGateway({
>    'only_books': only_books,
>    'books_and_authors': books_and_authors
> })
>
> The `only_books` method will return a list of book objects with no  
> author objects (as foreign keys are lazily loaded) whereas  
> `books_and_authors` will return books with author objects attached  
> to them. <-- Hope that all makes sense :)
>
> If you want this behaviour then apply the diff attached to your  
> pyamf tree. I have (lightly) tested for encoding but not decoding so  
> use with caution.
>
> If the patch seems reasonable we can get some tests for it and make  
> it part of 0.4.1.
>
> Joel, this should save you some time investigating the cache issue  
> you were having - hope it goes some way to solving your problem.
>
> Cheers,
>
> Nick
>
>
>
>
>
> On 26 Jan 2009, at 22:11, Bryan Hughes wrote:
>
> I don't mean to second guess, but are you certain DjangoAMF doesn't  
> handle ForeignKeys in the manner I described?  I read through this  
> post (http://sourceforge.jp/forum/forum.php?forum_id=10573&thread_id=16153 
> ) and the author implies this functionality has been made available  
> in DjangoAMF 0.7.
>
> Thank you again for your help.  Just getting frustrated with  
> something I was hoping would be straightforward.
>
>
> On Mon, Jan 26, 2009 at 4:44 PM, Joel <imlowdown@...> wrote:
> DjangoAMF doesn't handle it at all, you simply get the title_id:int  
> back (as you do with PyAMF). It is also unsupported (for all  
> practical purposes) and has some fairly crippling errors. Do not want.
>
> Nick explained to me earlier this month how to override the Cache  
> creation class to build your own custom cache. I would bet you could  
> do this and attach the object cleanly to the returned object. I  
> haven't tried this yet, but it is on my list of things to do. I will  
> report back if I have success. Will probably test it out tonight.
>
>
> On Mon, Jan 26, 2009 at 3:35 PM, Bryan Hughes <huuuze@...>  
> wrote:
> Thanks for the response.  From what I gather, adding the _cache  
> fields to my VO seems a little dirty.
>
> Does anyone know if DjangoAMF handles this dilemma in a cleaner  
> manner?
>
>
>
> On Mon, Jan 26, 2009 at 4:30 PM, Joel <imlowdown@...> wrote:
> "I personally hate this and wish it was either cleaner or more  
> controllable (in an easy way)."
>
> I should add, but not so much that I get off my lazy butt and  
> contribute to the project in a meaningful way. Thanks PyAmf dev  
> team, you guys are awesome! I would like to turn off the caching  
> globally though :>
>
>
> On Mon, Jan 26, 2009 at 3:24 PM, Joel <imlowdown@...> wrote:
> http://pastebin.com/m2ffcb77d
>
> I use these methods to grab related models and whatnot.
>
>
> ReferenceError: Error #1056: Cannot create property _title_cache on  
> com.myproject.models.vo.BookVO
>
> If you create a TitleVO object and then make a _title_cache:TitleVO  
> property it will do some ORM bits. I personally hate this and wish  
> it was either cleaner or more controllable (in an easy way).
>
> -joel
>
>
> On Mon, Jan 26, 2009 at 3:01 PM, Bryan Hughes <huuuze@...>  
> wrote:
> I need some help!  Please see the question I posted here:
>
> http://stackoverflow.com/questions/481110/how-can-i-use-flex-to-access-foreign-keyed-fields-in-django
>
> Does anyone know of a solution?  The one posted in the thread  
> results in the following error:
>
> ReferenceError: Error #1056: Cannot create property _title_cache on  
> com.myproject.models.vo.BookVO
>
> _______________________________________________
> PyAMF users mailing list - users@...
> http://lists.pyamf.org/mailman/listinfo/users
>
>
>
>
> _______________________________________________
> PyAMF users mailing list - users@...
> http://lists.pyamf.org/mailman/listinfo/users
>
>
>
> _______________________________________________
> PyAMF users mailing list - users@...
> http://lists.pyamf.org/mailman/listinfo/users
>
>
>
> _______________________________________________
> PyAMF users mailing list - users@...
> http://lists.pyamf.org/mailman/listinfo/users
>
>
> _______________________________________________
> PyAMF users mailing list - users@...
> http://lists.pyamf.org/mailman/listinfo/users
>
>
> _______________________________________________
> PyAMF users mailing list - users@...
> http://lists.pyamf.org/mailman/listinfo/users
>
>
> _______________________________________________
> PyAMF users mailing list - users@...
> http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

django-foreignkey-no-references.diff (1K) Download Attachment

Server 500 Errors when I try to up to 0.4.2 (still)

by Joel Hooks-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

So I dropped this and have just dealt with the _*_cache properties on my objects, but now it is becoming a real bandwidth/performance drain on my app.

After I up to 0.4.2 it throws 500 errors. At r2146 where I have been resting for some time, it works fine, but doesn't give me the joy of stripping the _*_cache props, or any of the other cool stuff you guys have worked so hard on. The request immediately preceding this request went through and delivered my object as expected.

Request:
This is the request:
POST /app/gateway/ HTTP/1.1
Host: myserver.com
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; en-us) AppleWebKit/530.18 (KHTML, like Gecko) Version/4.0.1 Safari/530.18
Content-Type: application/x-amf
Accept: */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Cookie: sessionid=2eb0e2332gdsg3447b9b190c
Pragma: no-cache
Content-Length: 97
Connection: keep-alive

retrieveStudioConfig/2
?retrieveStudioWatermark/3
?

Response:
HTTP/1.1 500 INTERNAL SERVER ERROR
Date: Mon, 22 Jun 2009 00:09:00 GMT
Server: Apache
Vary: Cookie
Content-Length: 64
Connection: close
Content-Type: text/plain

500 Internal Server Error

The request was unable to be encoded.

try:
    pyamf.register_class( User,                        'django.contrib.auth.models.User')
except ValueError:
    print "Classes already registered"

I'm registering all of my models in this fashion.

Joel Hooks (@jhooks)
http://joelhooks.com




On Feb 9, 2009, at 3:09 AM, Nick Joyce wrote:

Hmm, that is definitely not the desired behaviour.

I have attached a patch that strips out all django ForeignKey fields, it replaces the previous patch I supplied.

You can control the attributes that PyAMF encodes by supplying the attribute list that you want to encode through the register_class function. An example:

class Author(models.Model):
   name = models.StringField(max_length=255)

class Book(models.Model):
   name = models.StringField(max_length=255)
   do_not_include_this_property = models.StringField(max_length=10)
   author = models.ForeignKey(Author)

pyamf.register_class(Author, 'foo.bar.Author')
pyamf.register_class(Book, 'foo.bar.Book', attrs=['name', 'author'])

If you know your AMF, then attrs actually supplies a list of static attributes for the class (specific to AMF3 only) so in supplying that list, you guarantee that each instance of that class encoded/decoded has that list of attributes, which in Django's ORM is not a problem.

I am currently toying with the idea of an exclude_attr option so that you don't have to repeat yourself too much.

Can you send me a dump of the request/response that causes that 500? Is there a traceback?

Thanks!

Nick

On 8 Feb 2009, at 19:00, joelhooks wrote:

Nick,

This failed on the following model with a 'cannot encode' 500 error:

def get_studio_watermark(instance, filename):
   return 'watermarks/%s/%s' % (instance.id, filename)

class StudioWatermark(models.Model):
   studio              = models.ForeignKey(Studio, related_name="watermark", unique=True)
   image               = models.ImageField(upload_to=get_studio_watermark,blank=True,null=True)
   text                = models.CharField(max_length=64)
   def __unicode__(self):
       return '%s Watermark' % (self.studio.name)

That said, it worked on my other models as expected (I don't know how to test what the problem might be), but what I want to do is completely eliminate the cache altogether. I have some models that are a bit recursive, and it jumps my transfer of objects from a couple of hundred kB to a whopping 30mb of redundant data. obviously that is less than optimum.

Can I somehow adapt what you have done to completely strip the cache feature altogether?

Cheers,

Joel

On Mon, Jan 26, 2009 at 5:57 PM, Nick Joyce <nick@...> wrote:
Hi Bryan,

Welcome!

I hadn't realised that foreign key relationships were not being followed on encoding.

I have spent some time putting together an adapter that support django foreign keys out of the box without you (the user) having to do anything except provide a `select_related`.

An example:

# models

class Author(models.Model):
  name = models.CharField(max_length=100)

class Book(models.Model):
  title = models.CharField(max_length=50)
  author = models.ForeignKey(Author)

# views
import pyamf
from pyamf.remoting.gateway.django import DjangoGateway

from myproject.myapp.models import Book

def only_books():
  return Book.objects.all()

def books_and_authors():
  return Book.objects.select_related().all()

gateway = DjangoGateway({
  'only_books': only_books,
  'books_and_authors': books_and_authors
})

The `only_books` method will return a list of book objects with no author objects (as foreign keys are lazily loaded) whereas `books_and_authors` will return books with author objects attached to them. <-- Hope that all makes sense :)

If you want this behaviour then apply the diff attached to your pyamf tree. I have (lightly) tested for encoding but not decoding so use with caution.

If the patch seems reasonable we can get some tests for it and make it part of 0.4.1.

Joel, this should save you some time investigating the cache issue you were having - hope it goes some way to solving your problem.

Cheers,

Nick





On 26 Jan 2009, at 22:11, Bryan Hughes wrote:

I don't mean to second guess, but are you certain DjangoAMF doesn't handle ForeignKeys in the manner I described?  I read through this post (http://sourceforge.jp/forum/forum.php?forum_id=10573&thread_id=16153) and the author implies this functionality has been made available in DjangoAMF 0.7.

Thank you again for your help.  Just getting frustrated with something I was hoping would be straightforward.


On Mon, Jan 26, 2009 at 4:44 PM, Joel <imlowdown@...> wrote:
DjangoAMF doesn't handle it at all, you simply get the title_id:int back (as you do with PyAMF). It is also unsupported (for all practical purposes) and has some fairly crippling errors. Do not want.

Nick explained to me earlier this month how to override the Cache creation class to build your own custom cache. I would bet you could do this and attach the object cleanly to the returned object. I haven't tried this yet, but it is on my list of things to do. I will report back if I have success. Will probably test it out tonight.


On Mon, Jan 26, 2009 at 3:35 PM, Bryan Hughes <huuuze@...> wrote:
Thanks for the response.  From what I gather, adding the _cache fields to my VO seems a little dirty.

Does anyone know if DjangoAMF handles this dilemma in a cleaner manner?



On Mon, Jan 26, 2009 at 4:30 PM, Joel <imlowdown@...> wrote:
"I personally hate this and wish it was either cleaner or more controllable (in an easy way)."

I should add, but not so much that I get off my lazy butt and contribute to the project in a meaningful way. Thanks PyAmf dev team, you guys are awesome! I would like to turn off the caching globally though :>


On Mon, Jan 26, 2009 at 3:24 PM, Joel <imlowdown@...> wrote:
http://pastebin.com/m2ffcb77d

I use these methods to grab related models and whatnot.


ReferenceError: Error #1056: Cannot create property _title_cache on com.myproject.models.vo.BookVO

If you create a TitleVO object and then make a _title_cache:TitleVO property it will do some ORM bits. I personally hate this and wish it was either cleaner or more controllable (in an easy way).

-joel


On Mon, Jan 26, 2009 at 3:01 PM, Bryan Hughes <huuuze@...> wrote:
I need some help!  Please see the question I posted here:

http://stackoverflow.com/questions/481110/how-can-i-use-flex-to-access-foreign-keyed-fields-in-django

Does anyone know of a solution?  The one posted in the thread results in the following error:

ReferenceError: Error #1056: Cannot create property _title_cache on com.myproject.models.vo.BookVO

_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users




_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users


_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users


_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users


_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users


_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

Re: Server 500 Errors when I try to up to 0.4.2 (still)

by lists-144 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Joel,

did you ever sort this problem out (or open a ticket)?

Cheers,

Thijs

On 22 Jun 2009, at 01:24, Joel Hooks wrote:

So I dropped this and have just dealt with the _*_cache properties on my objects, but now it is becoming a real bandwidth/performance drain on my app.

After I up to 0.4.2 it throws 500 errors. At r2146 where I have been resting for some time, it works fine, but doesn't give me the joy of stripping the _*_cache props, or any of the other cool stuff you guys have worked so hard on. The request immediately preceding this request went through and delivered my object as expected.

Request:
This is the request:
POST /app/gateway/ HTTP/1.1
Host: myserver.com
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; en-us) AppleWebKit/530.18 (KHTML, like Gecko) Version/4.0.1 Safari/530.18
Content-Type: application/x-amf
Accept: */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Cookie: sessionid=2eb0e2332gdsg3447b9b190c
Pragma: no-cache
Content-Length: 97
Connection: keep-alive

retrieveStudioConfig/2
?retrieveStudioWatermark/3
?

Response:
HTTP/1.1 500 INTERNAL SERVER ERROR
Date: Mon, 22 Jun 2009 00:09:00 GMT
Server: Apache
Vary: Cookie
Content-Length: 64
Connection: close
Content-Type: text/plain

500 Internal Server Error

The request was unable to be encoded.

try:
    pyamf.register_class( User,                        'django.contrib.auth.models.User')
except ValueError:
    print "Classes already registered"

I'm registering all of my models in this fashion.

Joel Hooks (@jhooks)
http://joelhooks.com




On Feb 9, 2009, at 3:09 AM, Nick Joyce wrote:

Hmm, that is definitely not the desired behaviour.

I have attached a patch that strips out all django ForeignKey fields, it replaces the previous patch I supplied.

You can control the attributes that PyAMF encodes by supplying the attribute list that you want to encode through the register_class function. An example:

class Author(models.Model):
   name = models.StringField(max_length=255)

class Book(models.Model):
   name = models.StringField(max_length=255)
   do_not_include_this_property = models.StringField(max_length=10)
   author = models.ForeignKey(Author)

pyamf.register_class(Author, 'foo.bar.Author')
pyamf.register_class(Book, 'foo.bar.Book', attrs=['name', 'author'])

If you know your AMF, then attrs actually supplies a list of static attributes for the class (specific to AMF3 only) so in supplying that list, you guarantee that each instance of that class encoded/decoded has that list of attributes, which in Django's ORM is not a problem.

I am currently toying with the idea of an exclude_attr option so that you don't have to repeat yourself too much.

Can you send me a dump of the request/response that causes that 500? Is there a traceback?

Thanks!

Nick

On 8 Feb 2009, at 19:00, joelhooks wrote:

Nick,

This failed on the following model with a 'cannot encode' 500 error:

def get_studio_watermark(instance, filename):
   return 'watermarks/%s/%s' % (instance.id, filename)

class StudioWatermark(models.Model):
   studio              = models.ForeignKey(Studio, related_name="watermark", unique=True)
   image               = models.ImageField(upload_to=get_studio_watermark,blank=True,null=True)
   text                = models.CharField(max_length=64)
   def __unicode__(self):
       return '%s Watermark' % (self.studio.name)

That said, it worked on my other models as expected (I don't know how to test what the problem might be), but what I want to do is completely eliminate the cache altogether. I have some models that are a bit recursive, and it jumps my transfer of objects from a couple of hundred kB to a whopping 30mb of redundant data. obviously that is less than optimum.

Can I somehow adapt what you have done to completely strip the cache feature altogether?

Cheers,

Joel

On Mon, Jan 26, 2009 at 5:57 PM, Nick Joyce <nick@...> wrote:
Hi Bryan,

Welcome!

I hadn't realised that foreign key relationships were not being followed on encoding.

I have spent some time putting together an adapter that support django foreign keys out of the box without you (the user) having to do anything except provide a `select_related`.

An example:

# models

class Author(models.Model):
  name = models.CharField(max_length=100)

class Book(models.Model):
  title = models.CharField(max_length=50)
  author = models.ForeignKey(Author)

# views
import pyamf
from pyamf.remoting.gateway.django import DjangoGateway

from myproject.myapp.models import Book

def only_books():
  return Book.objects.all()

def books_and_authors():
  return Book.objects.select_related().all()

gateway = DjangoGateway({
  'only_books': only_books,
  'books_and_authors': books_and_authors
})

The `only_books` method will return a list of book objects with no author objects (as foreign keys are lazily loaded) whereas `books_and_authors` will return books with author objects attached to them. <-- Hope that all makes sense :)

If you want this behaviour then apply the diff attached to your pyamf tree. I have (lightly) tested for encoding but not decoding so use with caution.

If the patch seems reasonable we can get some tests for it and make it part of 0.4.1.

Joel, this should save you some time investigating the cache issue you were having - hope it goes some way to solving your problem.

Cheers,

Nick





On 26 Jan 2009, at 22:11, Bryan Hughes wrote:

I don't mean to second guess, but are you certain DjangoAMF doesn't handle ForeignKeys in the manner I described?  I read through this post (http://sourceforge.jp/forum/forum.php?forum_id=10573&thread_id=16153) and the author implies this functionality has been made available in DjangoAMF 0.7.

Thank you again for your help.  Just getting frustrated with something I was hoping would be straightforward.


On Mon, Jan 26, 2009 at 4:44 PM, Joel <imlowdown@...> wrote:
DjangoAMF doesn't handle it at all, you simply get the title_id:int back (as you do with PyAMF). It is also unsupported (for all practical purposes) and has some fairly crippling errors. Do not want.

Nick explained to me earlier this month how to override the Cache creation class to build your own custom cache. I would bet you could do this and attach the object cleanly to the returned object. I haven't tried this yet, but it is on my list of things to do. I will report back if I have success. Will probably test it out tonight.


On Mon, Jan 26, 2009 at 3:35 PM, Bryan Hughes <huuuze@...> wrote:
Thanks for the response.  From what I gather, adding the _cache fields to my VO seems a little dirty.

Does anyone know if DjangoAMF handles this dilemma in a cleaner manner?



On Mon, Jan 26, 2009 at 4:30 PM, Joel <imlowdown@...> wrote:
"I personally hate this and wish it was either cleaner or more controllable (in an easy way)."

I should add, but not so much that I get off my lazy butt and contribute to the project in a meaningful way. Thanks PyAmf dev team, you guys are awesome! I would like to turn off the caching globally though :>


On Mon, Jan 26, 2009 at 3:24 PM, Joel <imlowdown@...> wrote:
http://pastebin.com/m2ffcb77d

I use these methods to grab related models and whatnot.


ReferenceError: Error #1056: Cannot create property _title_cache on com.myproject.models.vo.BookVO

If you create a TitleVO object and then make a _title_cache:TitleVO property it will do some ORM bits. I personally hate this and wish it was either cleaner or more controllable (in an easy way).

-joel


On Mon, Jan 26, 2009 at 3:01 PM, Bryan Hughes <huuuze@...> wrote:
I need some help!  Please see the question I posted here:

http://stackoverflow.com/questions/481110/how-can-i-use-flex-to-access-foreign-keyed-fields-in-django

Does anyone know of a solution?  The one posted in the thread results in the following error:

ReferenceError: Error #1056: Cannot create property _title_cache on com.myproject.models.vo.BookVO

_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users




_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users


_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users


_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users


_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

PGP.sig (201 bytes) Download Attachment

Re: Server 500 Errors when I try to up to 0.4.2 (still)

by Joel Hooks-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Nick and I had some back and forth on this and he tracked down some of the issues related to ImageFields (and FileFields most likely as well) that use dynamic save locations. I passed off my source to him for debugging. He solved that portion, but then we ran into aother issue which is what Mark Mitchell has posted today (I think) relating to the order in which serialization happens an Django requiring a PK.

I did not submit a ticket for these issues.

Joel Hooks (@jhooks)
http://joelhooks.com




On Jun 26, 2009, at 1:06 PM, Thijs Triemstra | Collab wrote:

Hi Joel,

did you ever sort this problem out (or open a ticket)?

Cheers,

Thijs

On 22 Jun 2009, at 01:24, Joel Hooks wrote:

So I dropped this and have just dealt with the _*_cache properties on my objects, but now it is becoming a real bandwidth/performance drain on my app.

After I up to 0.4.2 it throws 500 errors. At r2146 where I have been resting for some time, it works fine, but doesn't give me the joy of stripping the _*_cache props, or any of the other cool stuff you guys have worked so hard on. The request immediately preceding this request went through and delivered my object as expected.

Request:
This is the request:
POST /app/gateway/ HTTP/1.1
Host: myserver.com
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; en-us) AppleWebKit/530.18 (KHTML, like Gecko) Version/4.0.1 Safari/530.18
Content-Type: application/x-amf
Accept: */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Cookie: sessionid=2eb0e2332gdsg3447b9b190c
Pragma: no-cache
Content-Length: 97
Connection: keep-alive

retrieveStudioConfig/2
?retrieveStudioWatermark/3
?

Response:
HTTP/1.1 500 INTERNAL SERVER ERROR
Date: Mon, 22 Jun 2009 00:09:00 GMT
Server: Apache
Vary: Cookie
Content-Length: 64
Connection: close
Content-Type: text/plain

500 Internal Server Error

The request was unable to be encoded.

try:
    pyamf.register_class( User,                        'django.contrib.auth.models.User')
except ValueError:
    print "Classes already registered"

I'm registering all of my models in this fashion.

Joel Hooks (@jhooks)
http://joelhooks.com




On Feb 9, 2009, at 3:09 AM, Nick Joyce wrote:

Hmm, that is definitely not the desired behaviour.

I have attached a patch that strips out all django ForeignKey fields, it replaces the previous patch I supplied.

You can control the attributes that PyAMF encodes by supplying the attribute list that you want to encode through the register_class function. An example:

class Author(models.Model):
   name = models.StringField(max_length=255)

class Book(models.Model):
   name = models.StringField(max_length=255)
   do_not_include_this_property = models.StringField(max_length=10)
   author = models.ForeignKey(Author)

pyamf.register_class(Author, 'foo.bar.Author')
pyamf.register_class(Book, 'foo.bar.Book', attrs=['name', 'author'])

If you know your AMF, then attrs actually supplies a list of static attributes for the class (specific to AMF3 only) so in supplying that list, you guarantee that each instance of that class encoded/decoded has that list of attributes, which in Django's ORM is not a problem.

I am currently toying with the idea of an exclude_attr option so that you don't have to repeat yourself too much.

Can you send me a dump of the request/response that causes that 500? Is there a traceback?

Thanks!

Nick

On 8 Feb 2009, at 19:00, joelhooks wrote:

Nick,

This failed on the following model with a 'cannot encode' 500 error:

def get_studio_watermark(instance, filename):
   return 'watermarks/%s/%s' % (instance.id, filename)

class StudioWatermark(models.Model):
   studio              = models.ForeignKey(Studio, related_name="watermark", unique=True)
   image               = models.ImageField(upload_to=get_studio_watermark,blank=True,null=True)
   text                = models.CharField(max_length=64)
   def __unicode__(self):
       return '%s Watermark' % (self.studio.name)

That said, it worked on my other models as expected (I don't know how to test what the problem might be), but what I want to do is completely eliminate the cache altogether. I have some models that are a bit recursive, and it jumps my transfer of objects from a couple of hundred kB to a whopping 30mb of redundant data. obviously that is less than optimum.

Can I somehow adapt what you have done to completely strip the cache feature altogether?

Cheers,

Joel

On Mon, Jan 26, 2009 at 5:57 PM, Nick Joyce <nick@...> wrote:
Hi Bryan,

Welcome!

I hadn't realised that foreign key relationships were not being followed on encoding.

I have spent some time putting together an adapter that support django foreign keys out of the box without you (the user) having to do anything except provide a `select_related`.

An example:

# models

class Author(models.Model):
  name = models.CharField(max_length=100)

class Book(models.Model):
  title = models.CharField(max_length=50)
  author = models.ForeignKey(Author)

# views
import pyamf
from pyamf.remoting.gateway.django import DjangoGateway

from myproject.myapp.models import Book

def only_books():
  return Book.objects.all()

def books_and_authors():
  return Book.objects.select_related().all()

gateway = DjangoGateway({
  'only_books': only_books,
  'books_and_authors': books_and_authors
})

The `only_books` method will return a list of book objects with no author objects (as foreign keys are lazily loaded) whereas `books_and_authors` will return books with author objects attached to them. <-- Hope that all makes sense :)

If you want this behaviour then apply the diff attached to your pyamf tree. I have (lightly) tested for encoding but not decoding so use with caution.

If the patch seems reasonable we can get some tests for it and make it part of 0.4.1.

Joel, this should save you some time investigating the cache issue you were having - hope it goes some way to solving your problem.

Cheers,

Nick





On 26 Jan 2009, at 22:11, Bryan Hughes wrote:

I don't mean to second guess, but are you certain DjangoAMF doesn't handle ForeignKeys in the manner I described?  I read through this post (http://sourceforge.jp/forum/forum.php?forum_id=10573&thread_id=16153) and the author implies this functionality has been made available in DjangoAMF 0.7.

Thank you again for your help.  Just getting frustrated with something I was hoping would be straightforward.


On Mon, Jan 26, 2009 at 4:44 PM, Joel <imlowdown@...> wrote:
DjangoAMF doesn't handle it at all, you simply get the title_id:int back (as you do with PyAMF). It is also unsupported (for all practical purposes) and has some fairly crippling errors. Do not want.

Nick explained to me earlier this month how to override the Cache creation class to build your own custom cache. I would bet you could do this and attach the object cleanly to the returned object. I haven't tried this yet, but it is on my list of things to do. I will report back if I have success. Will probably test it out tonight.


On Mon, Jan 26, 2009 at 3:35 PM, Bryan Hughes <huuuze@...> wrote:
Thanks for the response.  From what I gather, adding the _cache fields to my VO seems a little dirty.

Does anyone know if DjangoAMF handles this dilemma in a cleaner manner?



On Mon, Jan 26, 2009 at 4:30 PM, Joel <imlowdown@...> wrote:
"I personally hate this and wish it was either cleaner or more controllable (in an easy way)."

I should add, but not so much that I get off my lazy butt and contribute to the project in a meaningful way. Thanks PyAmf dev team, you guys are awesome! I would like to turn off the caching globally though :>


On Mon, Jan 26, 2009 at 3:24 PM, Joel <imlowdown@...> wrote:
http://pastebin.com/m2ffcb77d

I use these methods to grab related models and whatnot.


ReferenceError: Error #1056: Cannot create property _title_cache on com.myproject.models.vo.BookVO

If you create a TitleVO object and then make a _title_cache:TitleVO property it will do some ORM bits. I personally hate this and wish it was either cleaner or more controllable (in an easy way).

-joel


On Mon, Jan 26, 2009 at 3:01 PM, Bryan Hughes <huuuze@...> wrote:
I need some help!  Please see the question I posted here:

http://stackoverflow.com/questions/481110/how-can-i-use-flex-to-access-foreign-keyed-fields-in-django

Does anyone know of a solution?  The one posted in the thread results in the following error:

ReferenceError: Error #1056: Cannot create property _title_cache on com.myproject.models.vo.BookVO

_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users




_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users



_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users


_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users


_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users


_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users


_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users