Skip to content

Commit

Permalink
SA20: Restore backward-compatibility with SQLAlchemy 1.3
Browse files Browse the repository at this point in the history
Resolve import of `declarative_base`. For SA13, it is in
`sqlalchemy.ext.declarative`, while it is in `sqlalchemy.orm` on more
recent versions of SA.
  • Loading branch information
amotl committed Dec 29, 2022
1 parent 10eb284 commit 5bff9d2
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 14 deletions.
6 changes: 5 additions & 1 deletion docs/by-example/sqlalchemy/advanced-querying.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ Introduction
Import the relevant symbols:

>>> import sqlalchemy as sa
>>> from sqlalchemy.orm import declarative_base, sessionmaker
>>> from sqlalchemy.orm import sessionmaker
>>> try:
... from sqlalchemy.orm import declarative_base
... except ImportError:
... from sqlalchemy.ext.declarative import declarative_base
>>> from uuid import uuid4

Establish a connection to the database, see also :ref:`sa:engines_toplevel`
Expand Down
6 changes: 5 additions & 1 deletion docs/by-example/sqlalchemy/crud.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ Import the relevant symbols:
>>> import sqlalchemy as sa
>>> from datetime import datetime
>>> from sqlalchemy import delete, func, text
>>> from sqlalchemy.orm import declarative_base, sessionmaker
>>> from sqlalchemy.orm import sessionmaker
>>> try:
... from sqlalchemy.orm import declarative_base
... except ImportError:
... from sqlalchemy.ext.declarative import declarative_base
>>> from crate.client.sqlalchemy.types import ObjectArray

Establish a connection to the database, see also :ref:`sa:engines_toplevel`
Expand Down
6 changes: 5 additions & 1 deletion docs/by-example/sqlalchemy/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ Introduction
Import the relevant symbols:

>>> import sqlalchemy as sa
>>> from sqlalchemy.orm import declarative_base, sessionmaker
>>> from sqlalchemy.orm import sessionmaker
>>> try:
... from sqlalchemy.orm import declarative_base
... except ImportError:
... from sqlalchemy.ext.declarative import declarative_base

Establish a connection to the database, see also :ref:`sa:engines_toplevel`
and :ref:`connect`:
Expand Down
6 changes: 5 additions & 1 deletion docs/by-example/sqlalchemy/working-with-types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ Import the relevant symbols:
>>> from datetime import datetime
>>> from geojson import Point, Polygon
>>> from sqlalchemy import delete, func, text
>>> from sqlalchemy.orm import declarative_base, sessionmaker
>>> from sqlalchemy.orm import sessionmaker
>>> from sqlalchemy.sql import operators
>>> try:
... from sqlalchemy.orm import declarative_base
... except ImportError:
... from sqlalchemy.ext.declarative import declarative_base
>>> from uuid import uuid4
>>> from crate.client.sqlalchemy.types import Object, ObjectArray
>>> from crate.client.sqlalchemy.types import Geopoint, Geoshape
Expand Down
6 changes: 5 additions & 1 deletion src/crate/client/sqlalchemy/tests/array_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@

import sqlalchemy as sa
from sqlalchemy.sql import operators
from sqlalchemy.orm import declarative_base, Session
from sqlalchemy.orm import Session
try:
from sqlalchemy.orm import declarative_base
except ImportError:
from sqlalchemy.ext.declarative import declarative_base

from crate.client.cursor import Cursor

Expand Down
6 changes: 5 additions & 1 deletion src/crate/client/sqlalchemy/tests/bulk_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
from unittest.mock import patch, MagicMock

import sqlalchemy as sa
from sqlalchemy.orm import declarative_base, Session
from sqlalchemy.orm import Session
try:
from sqlalchemy.orm import declarative_base
except ImportError:
from sqlalchemy.ext.declarative import declarative_base

from crate.client.cursor import Cursor

Expand Down
5 changes: 4 additions & 1 deletion src/crate/client/sqlalchemy/tests/create_table_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
# software solely pursuant to the terms of the relevant commercial agreement.

import sqlalchemy as sa
from sqlalchemy.orm import declarative_base
try:
from sqlalchemy.orm import declarative_base
except ImportError:
from sqlalchemy.ext.declarative import declarative_base

from crate.client.sqlalchemy.types import Object, ObjectArray, Geopoint
from crate.client.cursor import Cursor
Expand Down
6 changes: 5 additions & 1 deletion src/crate/client/sqlalchemy/tests/datetime_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@

import sqlalchemy as sa
from sqlalchemy.exc import DBAPIError
from sqlalchemy.orm import declarative_base, Session
from sqlalchemy.orm import Session
try:
from sqlalchemy.orm import declarative_base
except ImportError:
from sqlalchemy.ext.declarative import declarative_base

from crate.client.cursor import Cursor

Expand Down
6 changes: 5 additions & 1 deletion src/crate/client/sqlalchemy/tests/dialect_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
from crate.client.cursor import Cursor
from crate.client.sqlalchemy.types import Object
from sqlalchemy import inspect
from sqlalchemy.orm import declarative_base, Session
from sqlalchemy.orm import Session
try:
from sqlalchemy.orm import declarative_base
except ImportError:
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.testing import eq_, in_

FakeCursor = MagicMock(name='FakeCursor', spec=Cursor)
Expand Down
6 changes: 5 additions & 1 deletion src/crate/client/sqlalchemy/tests/dict_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@

import sqlalchemy as sa
from sqlalchemy.sql import select
from sqlalchemy.orm import declarative_base, Session
from sqlalchemy.orm import Session
try:
from sqlalchemy.orm import declarative_base
except ImportError:
from sqlalchemy.ext.declarative import declarative_base

from crate.client.sqlalchemy.types import Craty, ObjectArray
from crate.client.cursor import Cursor
Expand Down
5 changes: 4 additions & 1 deletion src/crate/client/sqlalchemy/tests/function_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
from unittest import TestCase

import sqlalchemy as sa
from sqlalchemy.orm import declarative_base
from sqlalchemy.sql.sqltypes import TIMESTAMP
try:
from sqlalchemy.orm import declarative_base
except ImportError:
from sqlalchemy.ext.declarative import declarative_base


class SqlAlchemyFunctionTest(TestCase):
Expand Down
6 changes: 5 additions & 1 deletion src/crate/client/sqlalchemy/tests/insert_from_select_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@
from unittest.mock import patch, MagicMock

import sqlalchemy as sa
from sqlalchemy.orm import declarative_base, Session
from sqlalchemy import select, insert
from sqlalchemy.orm import Session
try:
from sqlalchemy.orm import declarative_base
except ImportError:
from sqlalchemy.ext.declarative import declarative_base

from crate.client.cursor import Cursor

Expand Down
6 changes: 5 additions & 1 deletion src/crate/client/sqlalchemy/tests/match_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
from unittest.mock import MagicMock

import sqlalchemy as sa
from sqlalchemy.orm import declarative_base, Session
from sqlalchemy.orm import Session
try:
from sqlalchemy.orm import declarative_base
except ImportError:
from sqlalchemy.ext.declarative import declarative_base

from crate.client.sqlalchemy.types import Craty
from crate.client.sqlalchemy.predicates import match
Expand Down
6 changes: 5 additions & 1 deletion src/crate/client/sqlalchemy/tests/update_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
from crate.client.sqlalchemy.types import Object

import sqlalchemy as sa
from sqlalchemy.orm import declarative_base, Session
from sqlalchemy.orm import Session
try:
from sqlalchemy.orm import declarative_base
except ImportError:
from sqlalchemy.ext.declarative import declarative_base

from crate.client.cursor import Cursor

Expand Down

0 comments on commit 5bff9d2

Please sign in to comment.