Giter Site home page Giter Site logo

django-conn-pool's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

django-conn-pool's Issues

Error when doing tests: KeyError: 'db'

When doing tests with pytest I have this error:

../../.venvs/mb-back/lib/python3.6/site-packages/django/test/utils.py:174: in setup_databases
    serialize=connection.settings_dict.get('TEST', {}).get('SERIALIZE', True),
../../.venvs/mb-back/lib/python3.6/site-packages/django/db/backends/base/creation.py:58: in create_test_db
    self._create_test_db(verbosity, autoclobber, keepdb)
../../.venvs/mb-back/lib/python3.6/site-packages/django/db/backends/base/creation.py:168: in _create_test_db
    with self._nodb_connection.cursor() as cursor:
../../.venvs/mb-back/lib/python3.6/site-packages/django/db/backends/base/base.py:256: in cursor
    return self._cursor()
../../.venvs/mb-back/lib/python3.6/site-packages/django/db/backends/base/base.py:233: in _cursor
    self.ensure_connection()
../../.venvs/mb-back/lib/python3.6/site-packages/django/db/backends/base/base.py:217: in ensure_connection
    self.connect()
../../.venvs/mb-back/lib/python3.6/site-packages/django/db/backends/base/base.py:195: in connect
    self.connection = self.get_new_connection(conn_params)
../../.venvs/mb-back/lib/python3.6/site-packages/django_conn_pool/mysql/base.py:64: in get_new_connection
    alias = self._get_alias_by_params(conn_params)
../../.venvs/mb-back/lib/python3.6/site-packages/django_conn_pool/mysql/base.py:80: in _get_alias_by_params
    target_str = ''.join([str(conn_params[_]) for _ in ['host', 'port', 'db', 'user', 'passwd']])
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

.0 = <tuple_iterator object at 0x7f35bffafac8>

>   target_str = ''.join([str(conn_params[_]) for _ in ['host', 'port', 'db', 'user', 'passwd']])
E   KeyError: 'db'

../../.venvs/mb-back/lib/python3.6/site-packages/django_conn_pool/mysql/base.py:80: KeyError

django==2.2.8
pytest==3.7.0

It works if I manually returning the "default" alias in django_conn_pool/mysql/base.py:80. I am not very deep into the internal functioning of Django but I will try to help. Setting TEST NAME param doesn't help.

Also manually setting another engine for tests solves this but I think it should be resolved in this library. This is the solution I used. In DATABASES settings:

'ENGINE': 'django_conn_pool.mysql' if not DEBUG else 'django.db.backends.mysql'

Multiple databases suport

I am using this engine for both my master and slave db configurations in setting.py, but whenever I try to execute a raw query via connections, the query is still being hit on master db.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.