daily pastebin goal


a guest Nov 28th, 2011 25 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (2011-11-28 19:27:13) jpk: I've got two models, Spot and Property.  Spot has a PointField called location and Property has no geometry fields.  If I do spots=Spot.objects.all(), then later Property.objects.filter(spot__in=spots), it works fine.  However, if I do spots=Spot.objects.filter(location__contained=Polygon(...)), then when Property.objects.filter(spot__in=spots) is called, I get "'str' object has no attribute 'ewkb''.  I had a GeoManager on Spot, but not Property.  Everything I've read tells me putting a GeoManager on Property fixes that, but that didn't seem to make a difference.  Any idea why?
  2. (2011-11-28 19:27:54) adamfast: jpk: you got cut off at "Everyt"
  3. (2011-11-28 19:28:02) adamfast: but I'll say that all models should have GeoManager
  4. (2011-11-28 19:28:11) adamfast: otherwise it doesn't know how to find stuff
  5. (2011-11-28 19:28:24) adamfast: NOT just the single model with the geometry field
  6. (2011-11-28 19:29:07) jpk: Dang, "Everything I've read tells me putting a GeoManager on Property fixes that, but that didn't seem to make a difference.  Any idea why?" :)
  7. (2011-11-28 19:29:24) adamfast: oh sorry. let me reread
  8. (2011-11-28 19:29:30) jpk: adamfast: Cut off at roughly the most important part of the question. :-P
  9. (2011-11-28 19:29:31) adamfast: I saw a cut off and didn't read up to it
  10. (2011-11-28 19:29:38) adamfast: indeed
  11. (2011-11-28 19:29:40) jpk: s'all good
  12. (2011-11-28 19:31:36) adamfast: ok so you added geomanager to the other one and still get the same error?
  13. (2011-11-28 19:31:47) jpk: Correct
  14. (2011-11-28 19:32:17) adamfast: ok. that's a different error than you'd expect from the geomanager issue anyway
  15. (2011-11-28 19:33:34) adamfast: I'm trying to remember what the right way out of this is
  16. (2011-11-28 19:33:47) adamfast: essentially it's trying to treat a string like it's a geometry
  17. (2011-11-28 19:36:08) jpk: Oh, correction.  It's not when Property.objects.filter() is called, it's when the iterable that that returns is iterated on.  
  18. (2011-11-28 19:38:06) jpk: http://pastebin.com/XL5XNDaN
  19. (2011-11-28 19:41:12) adamfast: can you try what it shows at "The above code fragment could also be written as follows:" https://docs.djangoproject.com/en/1.3/ref/models/querysets/#in
  20. (2011-11-28 19:41:28) adamfast: .values(pk) and then pass that in instead, basically
  21. (2011-11-28 19:41:40) adamfast: I'm curious if something isn't setting up the relationship / join properly
  22. (2011-11-28 19:45:34) jpk: http://pastebin.com/H9jHjWe0 Like that?
  23. (2011-11-28 19:46:14) adamfast: lol
  24. (2011-11-28 19:46:19) adamfast: the docs are WRONG
  25. (2011-11-28 19:46:37) adamfast: take .query off. that'll blow up because it's returning you a string of the SQL being run :)
  26. (2011-11-28 19:47:07) ***adamfast files a ticket. Good grief, what a process for six little characters
  27. (2011-11-28 19:47:33) adamfast: no wait
  28. (2011-11-28 19:47:50) jpk: Seems to do the same thing with/without .query, there.
  29. (2011-11-28 19:48:08) adamfast: maybe it does magic and if it gets a query object switches to a subselect. clever.
  30. (2011-11-28 19:48:28) adamfast: this is probably why they show it that way "If you pass in a ValuesQuerySet or ValuesListQuerySet (the result of calling values() or values_list() on a queryset) as the value to an __in lookup, you need to ensure you are only extracting one field in the result."
  31. (2011-11-28 19:48:40) adamfast: it blows up if you forget to only get the pk
  32. (2011-11-28 19:49:55) adamfast: but for you it blows up regardless
  33. (2011-11-28 19:50:46) adamfast: I suspect you've found a bug in the ORM
  34. (2011-11-28 19:51:53) jpk: Like, it works fine if I do spots = Spot.objects.all().  Only if I get spots using .filter(location__contained=...)
  35. (2011-11-28 19:52:31) adamfast: right
  36. (2011-11-28 19:53:58) jpk: Looks like any geo query does it.  Haven't tried all of them, but the first three or four do.
RAW Paste Data