[Django] #28515: mysql is checking all models also models that are mapped to POSTGIS

54 views
Skip to first unread message

Django

unread,
Aug 21, 2017, 7:42:19 PM8/21/17
to django-...@googlegroups.com
#28515: mysql is checking all models also models that are mapped to POSTGIS
-------------------------------------+-------------------------------------
Reporter: EDWIN | Owner: nobody
CUBILLOS |
Type: Bug | Status: new
Component: Database | Version: 1.11
layer (models, ORM) | Keywords: postgis, mysql,
Severity: Normal | multidatabase
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
**models**
{{{
from django.contrib.gis.db import models

class Ciudad(models.Model):
nombre = models.CharField(max_length=50, blank=True, null=True,
unique=True)
departamento = models.CharField(max_length=80, blank=True, null=True,
unique=True)
punto = models.PointField(blank=True, null=True)
polygon = models.PolygonField(blank=True, null=True)
precio_base = models.TextField(blank=True, null=True)
precio_yamimo = models.TextField(blank=True, null=True)


class Zona(models.Model):
nombre = models.CharField(max_length=50, blank=True, null=True,
unique=True)
polygon = models.PolygonField(blank=True, null=True)
ciudad = models.ForeignKey(Ciudad, blank=True, null=True)
recargo = models.IntegerField(default=0, blank=True, null=True)
}}}


**settings**

{{{
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'django.contrib.gis',
'compressor',
'django_extensions',

'djcelery',
'django_crontab',

'ciudades',
'api',

]

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'db_1',
'USER': 'root',
'PASSWORD': '****',
'HOST': '127.0.0.1',
'PORT': '3306',
},
'celery': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'db_cel',
'USER': 'root',
'PASSWORD': '****',
'HOST': '127.0.0.1',
'PORT': '3306',
},
'geozone': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'db_post',
'USER': 'root',
# 'PASSWORD': '****',
'HOST': '127.0.0.1',
'PORT': '5432',
}

}

DATABASE_ROUTERS = ['api.router.AutoRouter']

DB_APPS_MAPPING ={
"ciudades" : "geozone",
"django" : "celery",
"djcelery" : "celery"
}
}}}

**Router**

{{{
from settings import DB_APPS_MAPPING

## class for router app with db
class AutoRouter(object):

def db_for_read(self, model, **hints):
# if app_label is not in maps is default db (None
return DB_APPS_MAPPING.get(model._meta.app_label)

def db_for_write(self, model, **hints):
return DB_APPS_MAPPING.get(model._meta.app_label)

def allow_relation(self, obj1, obj2, **hints):
app1_db = DB_APPS_MAPPING.get(obj1._meta.app_label)
app2_db = DB_APPS_MAPPING.get(obj2._meta.app_label)
return True if app1_db == app2_db else None

def allow_migrate(self, db, app_label, model_name=None, **hints):
return DB_APPS_MAPPING.get(app_label)
}}}

**ERROR**
{{{
File "/Users/c02stf74fvh3/.virtualenvs/Rapigo/lib/python2.7/site-
packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/Users/c02stf74fvh3/.virtualenvs/Rapigo/lib/python2.7/site-
packages/django/core/checks/model_checks.py", line 30, in check_all_models
errors.extend(model.check(**kwargs))
File "/Users/c02stf74fvh3/.virtualenvs/Rapigo/lib/python2.7/site-
packages/django/db/models/base.py", line 1283, in check
errors.extend(cls._check_fields(**kwargs))
File "/Users/c02stf74fvh3/.virtualenvs/Rapigo/lib/python2.7/site-
packages/django/db/models/base.py", line 1358, in _check_fields
errors.extend(field.check(**kwargs))
File "/Users/c02stf74fvh3/.virtualenvs/Rapigo/lib/python2.7/site-
packages/django/db/models/fields/__init__.py", line 219, in check
errors.extend(self._check_backend_specific_checks(**kwargs))
File "/Users/c02stf74fvh3/.virtualenvs/Rapigo/lib/python2.7/site-
packages/django/db/models/fields/__init__.py", line 322, in
_check_backend_specific_checks
return connections[db].validation.check_field(self, **kwargs)
File "/Users/c02stf74fvh3/.virtualenvs/Rapigo/lib/python2.7/site-
packages/django/db/backends/mysql/validation.py", line 49, in check_field
field_type = field.db_type(self.connection)
File "/Users/c02stf74fvh3/.virtualenvs/Rapigo/lib/python2.7/site-
packages/django/contrib/gis/db/models/fields.py", line 126, in db_type
return connection.ops.geo_db_type(self)
AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'
}}}


== I have forked the repo from official Django
https://github.com/Cubillosxy/django , and I can pass this issue adding
some lines to
**lib/python2.7/site-packages/django/db/utils.py
**

line 294 in class **ConnectionRouter**
{{{
def allow_migrate(self, db, app_label, **hints):

try:
db_app_mapping = settings.DB_APPS_MAPPING.get(app_label,
DEFAULT_DB_ALIAS)
#if database are mapped and database has not app_label
if db_app_mapping != db:
return False
except AttributeError:
pass

for router in self.routers:
try:
method = router.allow_migrate
except AttributeError:
# If the router doesn't have a method, skip to the next
one.
continue

allow = method(db, app_label, **hints)

if allow is not None:
return allow
return True
}}}

I don't know if it was a good solution, or I am doing some wrong in my
code.

--
Ticket URL: <https://code.djangoproject.com/ticket/28515>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 21, 2017, 8:23:30 PM8/21/17
to django-...@googlegroups.com
#28515: mysql is checking all models also models that are mapped to POSTGIS
-------------------------------------+-------------------------------------
Reporter: EDWIN CUBILLOS | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution:
Keywords: postgis, mysql, | Triage Stage:
multidatabase | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

This looks similar to #28499. Can you confirm that you're using Django
1.11?

--
Ticket URL: <https://code.djangoproject.com/ticket/28515#comment:1>

Django

unread,
Aug 21, 2017, 8:28:52 PM8/21/17
to django-...@googlegroups.com
#28515: mysql is checking all models also models that are mapped to POSTGIS
-------------------------------------+-------------------------------------
Reporter: EDWIN CUBILLOS | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution:
Keywords: postgis, mysql, | Triage Stage:
multidatabase | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Old description:

New description:

version 1.11


**settings**

'djcelery',
'django_crontab',

'ciudades',
'api',

]

}

DATABASE_ROUTERS = ['api.router.AutoRouter']

**Router**

{{{
from settings import DB_APPS_MAPPING

--

Comment (by EDWIN CUBILLOS):

yes 1.11
sorry i forget add version ..

--
Ticket URL: <https://code.djangoproject.com/ticket/28515#comment:2>

Django

unread,
Aug 22, 2017, 7:51:36 AM8/22/17
to django-...@googlegroups.com
#28515: mysql is checking all models also models that are mapped to POSTGIS
-------------------------------------+-------------------------------------
Reporter: EDWIN CUBILLOS | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution: invalid

Keywords: postgis, mysql, | Triage Stage:
multidatabase | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => invalid


Comment:

I don't see anything that suggests a bug in Django. Maybe you need to
modify your router's `allow_migrate()` method as you suggested in the
description. Please see TicketClosingReasons/UseSupportChannels for ways
to get help debugging your code and reopen the ticket if you confirm a bug
in Django.

--
Ticket URL: <https://code.djangoproject.com/ticket/28515#comment:3>

Django

unread,
Aug 22, 2017, 9:26:02 AM8/22/17
to django-...@googlegroups.com
#28515: mysql is checking all models also models that are mapped to POSTGIS
-------------------------------------+-------------------------------------
Reporter: EDWIN CUBILLOS | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: postgis, mysql, | Triage Stage:
multidatabase | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by EDWIN CUBILLOS):

I believe that you don't understand my suggest ,
i don't suggest modify my router method
i suggest modify the **allow_migrate()** method in **django/db/utils.py**

--
Ticket URL: <https://code.djangoproject.com/ticket/28515#comment:4>

Django

unread,
Aug 22, 2017, 9:49:54 AM8/22/17
to django-...@googlegroups.com
#28515: mysql is checking all models also models that are mapped to POSTGIS
-------------------------------------+-------------------------------------
Reporter: EDWIN CUBILLOS | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: postgis, mysql, | Triage Stage:
multidatabase | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

Correct, I don't see the reason why we'd add those lines to Django.
`settings.DB_APPS_MAPPING` is something you've added, it's not an existing
setting in Django and I don't see a reason to add it.

--
Ticket URL: <https://code.djangoproject.com/ticket/28515#comment:5>

Django

unread,
Aug 22, 2017, 5:08:40 PM8/22/17
to django-...@googlegroups.com
#28515: mysql is checking all models also models that are mapped to POSTGIS
-------------------------------------+-------------------------------------
Reporter: EDWIN CUBILLOS | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: postgis, mysql, | Triage Stage:
multidatabase | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Shai Berger):

Hi Edwin,

To expand Tim's comment: Your router's `allow_migrate()` should return a
Boolean. Instead, it returns the app's database-name (from your
`DB_APPS_MAPPING`), which, for every app actually defined there, is
truthy.

--
Ticket URL: <https://code.djangoproject.com/ticket/28515#comment:6>

Django

unread,
Aug 22, 2017, 8:49:12 PM8/22/17
to django-...@googlegroups.com
#28515: mysql is checking all models also models that are mapped to POSTGIS
-------------------------------------+-------------------------------------
Reporter: EDWIN CUBILLOS | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: postgis, mysql, | Triage Stage:
multidatabase | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by EDWIN CUBILLOS):

oh , thanks
**Shai Berger**
that it is the answer,

--
Ticket URL: <https://code.djangoproject.com/ticket/28515#comment:7>

Reply all
Reply to author
Forward
0 new messages