| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
database.backend defaulted to "mysql", so a connection made without configuring a backend went to MySQL. It now defaults to "postgresql" on port 5432. MySQL stays a fully supported backend, selected with one setting. The port follows the backend unless it is set. The port was derived from the backend only when the settings were first built, so a backend set later, in datajoint.json or by assignment, kept the other backend's port: with the new default, backend "mysql" in datajoint.json would have connected to port 5432. The validator now recomputes a port that was not set whenever the backend changes. A port set by DJ_PORT, datajoint.json, or assignment is kept, and setting it to None returns it to the backend's default. When a connection fails and the backend is still the default, so that neither the backend argument nor the configuration chose one, the error is re-raised as a DataJointError that keeps the original message and adds: The default backend is postgresql since DataJoint 2.4; set database.backend='mysql' (DJ_BACKEND=mysql) for a MySQL server. The same applies when the adapter cannot be created, as when psycopg2 is not installed. The settings record which fields were set (pydantic's model_fields_set), so DJ_BACKEND, datajoint.json, dj.config assignment, and Instance(backend=...) all count as chosen, and with any of them the original error is raised unchanged. Instance no longer passes its config's backend to Connection as an argument, which hid whether it was chosen; Connection reads it from that config. save_template writes "backend": "postgresql" and port 5432. The settings docstring, the Connection and Instance docstrings, the CLI help, docker-compose.yaml, and CONTRIBUTING.md list PostgreSQL first. In the compose file the app service's DJ_HOST, DJ_USER, and DJ_PASS name the MySQL service, which the test suite reads as its MySQL server, so the service now sets DJ_BACKEND=mysql to match. Migration for MySQL users: select the backend with DJ_BACKEND=mysql, "backend": "mysql" under "database" in datajoint.json, dj.config["database.backend"] = "mysql" before connecting, or dj.Instance(..., backend="mysql"). The port then defaults to 3306; an explicit port is kept. A MySQL setup that sets no backend fails to connect with the message above. Tests: the MySQL-only fixtures no longer rely on the default. A session fixture, mysql_backend_config, selects MySQL in dj.config for the tests that connect through db_creds_root and db_creds_test. connection_root_bare and connection_test pass backend="mysql". The CLI test's subprocess sets DJ_BACKEND=mysql. connection_by_backend falls back to "postgresql". New unit tests, which need no server, check the default backend and port, that a port not set follows the backend (including backend "mysql" in datajoint.json), that a port that was set survives a change of backend, and that the hint appears for a failed connection or missing driver with the default backend. They also check that it does not appear when the backend comes from the argument, assignment, DJ_BACKEND, or datajoint.json, using a stub adapter and a real refused connection to a closed local port.
There was a problem hiding this comment.
Thanks @dimitri-yatsenko, the default-backend hint is a nice touch for the migration, and keying it off model_fields_set is a neat way to tell "chosen" from "defaulted".
Verified locally:
✅ Unit suite passes on this branch, and on master + #1628 + #1629 merged together
✅ An unset port follows the backend both ways; port=None returns it to the backend default; Instance(backend="mysql") and dj.conn() pick up the backend from config
One issue:
with dj.config.override(database__port=1234): ...
dj.config["database.backend"] = "mysql"Minor:
Let me know what you think!
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Closes #1627.
Summary
database.backend now defaults to "postgresql" on port 5432. MySQL remains a fully supported backend, selected with DJ_BACKEND=mysql or database.backend = "mysql". A connection that fails while the backend is still the default says so:
Changes
Tests that relied on MySQL being the default
New tests (no server needed)
Full suite (testcontainers, local): 1170 passed, 14 skipped.
Checked against real servers, with this branch merged with the drivers-as-extras PR and installed in clean virtual environments (no datajoint.json):
Migration for MySQL users
Use any one of:
The port then defaults to 3306, and an explicit port is kept.
Notes for review