Skip to content

Commit

Permalink
Updating to sqlalchemy 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbyt3r committed Aug 4, 2023
1 parent 903c767 commit 4f38e8f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
14 changes: 7 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
configobj==5.0.6
cherrypy==18.8.0
ws4py==0.5.1
SQLAlchemy==1.4.43
SQLAlchemy==2.0.19
six==1.16.0
Jinja2==3.1.2
rpctools==0.3.1
requests==2.28.1
requests==2.31.0
paver==1.3.4
wheel==0.37.1
pip==22.3
sh==1.14.3
wheel==0.41.0
pip==23.2.1
sh==2.0.4
python-prctl==1.8.1; 'linux' in sys_platform
psutil==5.9.3
redis==4.3.4
psutil==5.9.5
redis==4.6.0
2 changes: 1 addition & 1 deletion sideboard/lib/sa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def __init__(self, *args, **kwargs):
_declarative_constructor(self, *args, **kwargs)
for attr, col in self.__table__.columns.items():
if kwargs.get(attr) is None and col.default:
self.__dict__.setdefault(attr, col.default.execute())
self.__dict__.setdefault(attr, col.default.arg(col))

orig_kwargs['cls'] = Mixed
if 'name' not in orig_kwargs:
Expand Down
2 changes: 1 addition & 1 deletion sideboard/lib/sa/_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ def _resolve_comparison(cls, comparison, column, value):
if isinstance(value, dict):
model_class = Session.resolve_model(value.get('_model'))
field = value.get('select', 'id')
value = select([getattr(model_class, field)], cls._resolve_filters(value))
value = select(getattr(model_class, field)).where(cls._resolve_filters(value))

return {
'eq': lambda field, val: field == val,
Expand Down
3 changes: 2 additions & 1 deletion sideboard/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sqlalchemy
from sqlalchemy import event
from sqlalchemy.orm import sessionmaker
from sqlalchemy.pool import NullPool

from sideboard.lib import config, services

Expand Down Expand Up @@ -71,7 +72,7 @@ def patch_session(Session, request):

name = Session.__module__.split('.')[0]
db_path = '/tmp/{}.db'.format(name)
Session.engine = sqlalchemy.create_engine('sqlite+pysqlite:///' + db_path)
Session.engine = sqlalchemy.create_engine('sqlite+pysqlite:///' + db_path, poolclass=NullPool)
event.listen(Session.engine, 'connect', lambda conn, record: conn.execute('pragma foreign_keys=ON'))
Session.session_factory = sessionmaker(bind=Session.engine, autoflush=False, autocommit=False,
query_cls=Session.QuerySubclass)
Expand Down
7 changes: 4 additions & 3 deletions sideboard/tests/test_sa.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import sqlalchemy
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.pool import NullPool
from sqlalchemy.orm import relationship
from sqlalchemy.types import Boolean, Integer, UnicodeText
from sqlalchemy.schema import Column, CheckConstraint, ForeignKey, MetaData, Table, UniqueConstraint
Expand Down Expand Up @@ -121,10 +122,10 @@ def string_and_int_hybrid_property(self):

@string_and_int_hybrid_property.expression
def string_and_int_hybrid_property(cls):
return case([
return case(
(cls.string_model_attr == None, ''),
(cls.int_model_attr == None, '')
], else_=(cls.string_model_attr + ' ' + cls.int_model_attr))
, else_=(cls.string_model_attr + ' ' + cls.int_model_attr))

@property
def unsettable_property(self):
Expand All @@ -150,7 +151,7 @@ class BasicClassMixedIn(CrudableMixin, Base):


class Session(SessionManager):
engine = sqlalchemy.create_engine('sqlite:////tmp/test_sa.db')
engine = sqlalchemy.create_engine('sqlite:////tmp/test_sa.db', poolclass=NullPool)

class SessionMixin(object):
def user(self, name):
Expand Down

0 comments on commit 4f38e8f

Please sign in to comment.