Re: Seems like a geodjango bug with multiple databases

2015-02-21 Thread Luan Nguyen
Hi, sorry for my late response.

Thanks for replying.

I'm using django 1.7.4.

Going with this 
Room.objects.using('another').select_related('hotel').get(pk=10) is fine, I 
can then get room.hotel without any problem.

I also followed Jani's advice and changed default manager of Room to 
GeoManager, but still got that error.

@George: I actually had this issue in one of my app (running django 1.7), 
but not sure whether it's due to my code or django, so I set up a 
completely new project as described above (with django 1.7.4), and still 
get the error. Postgis is enabled on both databases (will get error if it 
doesn't anyway).

I was trying to trace back the code but don't have enough experience to 
fully understand the problem. I'll ask geodjango list as Collin suggested 
to see if someone experienced the same thing.

Luan

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bebe1636-c8a8-4026-bb11-578f29220149%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Seems like a geodjango bug with multiple databases

2015-02-20 Thread Jani Tiainen
On Wed, 18 Feb 2015 06:45:15 -0800 (PST)
Luan Nguyen  wrote:

> I'm using geodjango and multiple databases, and experiencing a quite weird 
> situation, I guess it's a kind of bug but not absolutely sure since I'm 
> pretty new to Django.
> 
> Here is how to reproduce the problem:
> - Set up another database besides default:
> DATABASES = {
> 'default': {
> 'ENGINE' : 'django.contrib.gis.db.backends.postgis' 
> ,
> 'NAME' : 'issue1',
> 'USER' : 'user',
> 'PASSWORD' : 'password',
> 'HOST' : '127.0.0.1',
> 'OPTIONS' : {
> 'autocommit' : True,
> }
> },
> 'another': {
> 'ENGINE' : 'django.contrib.gis.db.backends.postgis' 
> ,
> 'NAME' : 'issue2',
> 'USER' : 'user',
> 'PASSWORD' : 'password',
> 'HOST' : '127.0.0.1',
> 'OPTIONS' : {
> 'autocommit' : True,
> }
> },
> }
> 
> And two models:
> from django.db import models as default_models
> from django.contrib.gis.db import models
> # Create your models here.
> class Hotel(models.Model):
> hotel_name = models.CharField(max_length=255)
> objects = models.GeoManager()
> 
> class Room(models.Model):
> room_num = models.IntegerField()
> hotel = models.ForeignKey(Hotel, null=True, blank=True)

You don't have GeoManager on Room model? It's required to be default (first) 
manager if you do queries that even relate to geo-enabled model.

https://docs.djangoproject.com/en/1.7/ref/contrib/gis/model-api/#geomanager

And there reads: "It should also be noted that GeoManager is required even if 
the model does not have a geographic field itself, e.g., in the case of a 
ForeignKey relation to a model with a geographic field."
 
> Add data into issue2 database (leave issue1 blank), then go into shell:
> >>>h = Hotel.objects.using('another').all()[0]
> >>> h.id
> 9
> >>>h.room_set.all()[0].id  #=> room id 
> 10 links to hotel id 9
> 10
> >>>r = Room.objects.using('another').get(pk=10)
> >>>r.hotel
> Traceback (most recent call last):
> File "", line 1, in 
> File "/
> Applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.4/site-packages/django/db/models/fields/related.py
>  
> ",
>  
> line 572, in __get__
> rel_obj = qs.get()
> File "/
> Applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.4/site-packages/django/db/models/query.py
>  
> ",
>  
> line 357, in get
> self.model._meta.object_name)
> multi.models.DoesNotExist: Hotel matching query does not exist.
> 
> The thing is, if I create a hotel record on database issue1 with id of 9 
> then the last command works, so I guess it tried to look up in default 
> database. This doesn't have any problems if I use default manager for 
> Hotel, so I guess it's a bug?
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/daa291e8-bf87-422a-a8fc-b23038e94268%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


-- 
Jani Tiainen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20150220101236.1c721b6e%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: Seems like a geodjango bug with multiple databases

2015-02-19 Thread George Silva
I'm using with success two postgis enabled databases on a single
application, without quirks.

I have a read-only database, and a read/write database. No problems, so far.

On Thu, Feb 19, 2015 at 5:11 PM, Collin Anderson 
wrote:

> Hi,
>
> Interesting. What version of django is this?
>
> Here's something to try:
> Room.objects.using('another').select_related('hotel').get(pk=10)
>
> It could very well be an issue with GeoManager / GeoQuerySet.
>
> You also could ask on the geodjango list to see if anyone else has run
> into that.
>
> http://groups.google.com/group/geodjango
>
> Collin
>
>
> On Wednesday, February 18, 2015 at 9:45:15 AM UTC-5, Luan Nguyen wrote:
>>
>> I'm using geodjango and multiple databases, and experiencing a quite
>> weird situation, I guess it's a kind of bug but not absolutely sure since
>> I'm pretty new to Django.
>>
>> Here is how to reproduce the problem:
>> - Set up another database besides default:
>> DATABASES = {
>> 'default': {
>> 'ENGINE' : 'django.contrib.gis.db.backends.postgis'
>> ,
>> 'NAME' : 'issue1',
>> 'USER' : 'user',
>> 'PASSWORD' : 'password',
>> 'HOST' : '127.0.0.1',
>> 'OPTIONS' : {
>> 'autocommit' : True,
>> }
>> },
>> 'another': {
>> 'ENGINE' : 'django.contrib.gis.db.backends.postgis'
>> ,
>> 'NAME' : 'issue2',
>> 'USER' : 'user',
>> 'PASSWORD' : 'password',
>> 'HOST' : '127.0.0.1',
>> 'OPTIONS' : {
>> 'autocommit' : True,
>> }
>> },
>> }
>>
>> And two models:
>> from django.db import models as default_models
>> from django.contrib.gis.db import models
>> # Create your models here.
>> class Hotel(models.Model):
>> hotel_name = models.CharField(max_length=255)
>> objects = models.GeoManager()
>>
>> class Room(models.Model):
>> room_num = models.IntegerField()
>> hotel = models.ForeignKey(Hotel, null=True, blank=True)
>>
>> Add data into issue2 database (leave issue1 blank), then go into shell:
>> >>>h = Hotel.objects.using('another').all()[0]
>> >>> h.id
>> 9
>> >>>h.room_set.all()[0].id #=> room id 10 links to hotel id 9
>> 10
>> >>>r = Room.objects.using('another').get(pk=10)
>> >>>r.hotel
>> Traceback (most recent call last):
>> File "", line 1, in 
>> File "/Applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.
>> 4/site-packages/django/db/models/fields/related.py
>> ",
>> line 572, in __get__
>> rel_obj = qs.get()
>> File "/Applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.
>> 4/site-packages/django/db/models/query.py
>> ",
>> line 357, in get
>> self.model._meta.object_name)
>> multi.models.DoesNotExist: Hotel matching query does not exist.
>>
>> The thing is, if I create a hotel record on database issue1 with id of 9
>> then the last command works, so I guess it tried to look up in default
>> database. This doesn't have any problems if I use default manager for
>> Hotel, so I guess it's a bug?
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/64d0f22e-ce10-4626-beef-5f99c63de787%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
George R. C. Silva
SIGMA Consultoria

http://www.consultoriasigma.com.br/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGyPVTuc5ecd-1xBvTT-_GKSbAAmGAgY_w0qSE6QptAfkoweYw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Seems like a geodjango bug with multiple databases

2015-02-19 Thread Collin Anderson
Hi,

Interesting. What version of django is this?

Here's something to try:
Room.objects.using('another').select_related('hotel').get(pk=10)

It could very well be an issue with GeoManager / GeoQuerySet.

You also could ask on the geodjango list to see if anyone else has run into 
that.

http://groups.google.com/group/geodjango

Collin

On Wednesday, February 18, 2015 at 9:45:15 AM UTC-5, Luan Nguyen wrote:
>
> I'm using geodjango and multiple databases, and experiencing a quite weird 
> situation, I guess it's a kind of bug but not absolutely sure since I'm 
> pretty new to Django.
>
> Here is how to reproduce the problem:
> - Set up another database besides default:
> DATABASES = {
> 'default': {
> 'ENGINE' : 'django.contrib.gis.db.backends.postgis' 
> ,
> 'NAME' : 'issue1',
> 'USER' : 'user',
> 'PASSWORD' : 'password',
> 'HOST' : '127.0.0.1',
> 'OPTIONS' : {
> 'autocommit' : True,
> }
> },
> 'another': {
> 'ENGINE' : 'django.contrib.gis.db.backends.postgis' 
> ,
> 'NAME' : 'issue2',
> 'USER' : 'user',
> 'PASSWORD' : 'password',
> 'HOST' : '127.0.0.1',
> 'OPTIONS' : {
> 'autocommit' : True,
> }
> },
> }
>
> And two models:
> from django.db import models as default_models
> from django.contrib.gis.db import models
> # Create your models here.
> class Hotel(models.Model):
> hotel_name = models.CharField(max_length=255)
> objects = models.GeoManager()
>
> class Room(models.Model):
> room_num = models.IntegerField()
> hotel = models.ForeignKey(Hotel, null=True, blank=True)
>
> Add data into issue2 database (leave issue1 blank), then go into shell:
> >>>h = Hotel.objects.using('another').all()[0]
> >>> h.id
> 9
> >>>h.room_set.all()[0].id #=> room id 10 links to hotel id 9
> 10
> >>>r = Room.objects.using('another').get(pk=10)
> >>>r.hotel
> Traceback (most recent call last):
> File "", line 1, in 
> File "/
> Applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.4/site-packages/django/db/models/fields/related.py
>  
> ",
>  
> line 572, in __get__
> rel_obj = qs.get()
> File "/
> Applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.4/site-packages/django/db/models/query.py
>  
> ",
>  
> line 357, in get
> self.model._meta.object_name)
> multi.models.DoesNotExist: Hotel matching query does not exist.
>
> The thing is, if I create a hotel record on database issue1 with id of 9 
> then the last command works, so I guess it tried to look up in default 
> database. This doesn't have any problems if I use default manager for 
> Hotel, so I guess it's a bug?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/64d0f22e-ce10-4626-beef-5f99c63de787%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Seems like a geodjango bug with multiple databases

2015-02-18 Thread Luan Nguyen
I'm using geodjango and multiple databases, and experiencing a quite weird 
situation, I guess it's a kind of bug but not absolutely sure since I'm 
pretty new to Django.

Here is how to reproduce the problem:
- Set up another database besides default:
DATABASES = {
'default': {
'ENGINE' : 'django.contrib.gis.db.backends.postgis' 
,
'NAME' : 'issue1',
'USER' : 'user',
'PASSWORD' : 'password',
'HOST' : '127.0.0.1',
'OPTIONS' : {
'autocommit' : True,
}
},
'another': {
'ENGINE' : 'django.contrib.gis.db.backends.postgis' 
,
'NAME' : 'issue2',
'USER' : 'user',
'PASSWORD' : 'password',
'HOST' : '127.0.0.1',
'OPTIONS' : {
'autocommit' : True,
}
},
}

And two models:
from django.db import models as default_models
from django.contrib.gis.db import models
# Create your models here.
class Hotel(models.Model):
hotel_name = models.CharField(max_length=255)
objects = models.GeoManager()

class Room(models.Model):
room_num = models.IntegerField()
hotel = models.ForeignKey(Hotel, null=True, blank=True)

Add data into issue2 database (leave issue1 blank), then go into shell:
>>>h = Hotel.objects.using('another').all()[0]
>>> h.id
9
>>>h.room_set.all()[0].id  #=> room id 
10 links to hotel id 9
10
>>>r = Room.objects.using('another').get(pk=10)
>>>r.hotel
Traceback (most recent call last):
File "", line 1, in 
File "/
Applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.4/site-packages/django/db/models/fields/related.py
 
",
 
line 572, in __get__
rel_obj = qs.get()
File "/
Applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.4/site-packages/django/db/models/query.py
 
",
 
line 357, in get
self.model._meta.object_name)
multi.models.DoesNotExist: Hotel matching query does not exist.

The thing is, if I create a hotel record on database issue1 with id of 9 
then the last command works, so I guess it tried to look up in default 
database. This doesn't have any problems if I use default manager for 
Hotel, so I guess it's a bug?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/daa291e8-bf87-422a-a8fc-b23038e94268%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.