auvipy / django-sqlalchemy

Django ORM built on top of SQLalchemy core 2.0 for seamless integration of SQLAlchemy with Django 4.2+ PostgreSQL 14+ only for now. [pre POC now]

Home Page:https://pypi.org/project/django-sqlalchemy/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

'DatabaseWrapper' object has no attribute 'operators'

GoogleCodeExporter opened this issue · comments

I installed django_sqlalchemy in a old website with latest django version.

I not changed the models after the installation of django_sqlalchemy.

Sometime, when I do some query like filter(), all(), get() ecc., an error
appears. I do not know why.

"""
django/db/models/sql/where.py in make_atom(self, child, qn)
    117             extra = ''
    118
--> 119         if lookup_type in connection.operators:
    120             format = "%s %%s %s" %
(connection.ops.lookup_cast(lookup_type),
    121                     extra)
<type 'exceptions.AttributeError'>: 'DatabaseWrapper' object has no
attribute 'operators'
"""

So, I investigated below...

I opened django/db/backends/postgresql/base.py and I saw the attribute
"operators":
"""
operators = {
    'exact': '= %s',
    'iexact': 'ILIKE %s',
    'contains': 'LIKE %s',
    'icontains': 'ILIKE %s',
    'regex': '~ %s',
    'iregex': '~* %s',
    'gt': '> %s',
    'gte': '>= %s',
    'lt': '< %s',
    'lte': '<= %s',
    'startswith': 'LIKE %s',
    'endswith': 'LIKE %s',
    'istartswith': 'ILIKE %s',
    'iendswith': 'ILIKE %s',
}
"""

But the backend of django_sqlalchemy have not this attribute
(django_sqlalchemy/backend/base.py).

Versions used:
Django trunk r7519
Sqlalchemy v0.4.5
django_sqlalchemy mainline "commit 481f7d6aa3688fcbedcd19c72072c130cc2e5a09
Sun Apr 27 09:36:57 2008 -0400"

Original issue reported on code.google.com by davide.m...@gmail.com on 7 May 2008 at 6:39

This patch resolve the problem.

It require a settings.DJANGO_SQLALCHEMY_FALLBACK_ENGINE with the engine like the
standard use of settings.DATABASE_ENGINE.

I know that using the "operators" fields including django.db.backends.* engines 
is a
more elegant solution, but load all unused classes break the simplicity rule.

I aim to use django_sqlalchemy with mixed models without touching the common 
Django
and 3rd party apps.

Original comment by davide.m...@gmail.com on 7 May 2008 at 7:57

Attachments:

Thank you for the info.  I'm a little confused though.  What exactly did you 
setup if you're not using django-
sqlalchemy as the backend?  In other words, which parts did you specify in your 
settings that created this 
problem?

Original comment by mtr...@gmail.com on 9 May 2008 at 1:12

Thank you for your reply Mtrier.

Bellow I explicate better the situation, I'm sorry if I have a not good enough
english. ^_^

I added a new test application with "from django_sqlalchemy import models".
I do NOT changed my models with "from django.db import models".

The test application seems to run well (I test it only in few queries).
The others applications run sometimes well and sometimes not (see the error in 
the
first post). There are other errors but this, in this ticket, is the most 
important.

I use this mixed models because my websites have the same standard applications 
and I
have to upgrade often these applications and the Django libs, so I can not 
change the
models of every application and every Django installation in order to use "from
django_sqlalchemy import models" and fix all the custom fields. I think that 
this is
the aim of the project: installation simple and backward compatible as possible.

This is in my settings.py file:
"""
DATABASE_ENGINE = 'django_sqlalchemy.backend'
DJANGO_SQLALCHEMY_DBURI = 'postgres://xxxxxxxx:xxxxxxxx@localhost/my_database' 
#I use
prostgresql_psycopg2

INTSATTEL_APPS = (
    'django_sqlalchemy',
    ...
)
"""

Is possible that I do something wrong, or that I misunderstand the aim of the 
project. :/

Original comment by davide.m...@gmail.com on 9 May 2008 at 12:20

Okay thanks for the explanation.  That makes more sense.  I'm actually working 
on this piece right now.   At the 
moment you CANNOT use models that do not have the statement "from 
django_sqlalchemy import models".  As 
soon as I get the work done that is the goal of the project.

Original comment by mtr...@gmail.com on 10 May 2008 at 3:03

  • Added labels: O
It's difficult to me understand well the new Djanto QuerySet because the
documentation lack, but I'm available to help you on doing something about this 
feature.

In every case, thank you Mtrier.

Original comment by davide.m...@gmail.com on 10 May 2008 at 8:40