Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade to support SQLAlchemy 1.4 #1

Open
wants to merge 4 commits into
base: mysql
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions pgcontents/pgmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"""
from __future__ import unicode_literals
from itertools import chain

from sqlalchemy.orm import Session
from tornado import web

from .api_utils import (
Expand Down Expand Up @@ -331,13 +333,14 @@ def save(self, model, path):
if model['type'] not in ('file', 'directory', 'notebook'):
self.do_400("Unhandled contents type: %s" % model['type'])
try:
with self.engine.begin() as db:
session = Session(self.engine)
with session.begin():
if model['type'] == 'notebook':
validation_message = self._save_notebook(db, model, path)
validation_message = self._save_notebook(session, model, path)
elif model['type'] == 'file':
validation_message = self._save_file(db, model, path)
validation_message = self._save_file(session, model, path)
else:
validation_message = self._save_directory(db, path)
validation_message = self._save_directory(session, path)
except (web.HTTPError, PathOutsideRoot):
raise
except FileTooLarge:
Expand Down
45 changes: 23 additions & 22 deletions pgcontents/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ def _file_default_fields():
files.c.name,
files.c.created_at,
files.c.parent_name,
files.c.user_id,
]


Expand Down Expand Up @@ -472,32 +473,32 @@ def save_file(db, user_id, path, content, max_size_bytes):
"""
check_content(content, max_size_bytes)
directory, name = split_api_filepath(path)
with db.begin_nested() as savepoint:
try:
savepoint = db.begin_nested()
try:
res = db.execute(
files.insert().values(
name=name,
user_id=user_id,
parent_name=directory,
content=content,
)
)
except IntegrityError as error:
# The file already exists, so overwrite its content with the newer
# version.
if is_unique_violation(error):
savepoint.rollback()
res = db.execute(
files.insert().values(
name=name,
user_id=user_id,
parent_name=directory,
files.update().where(
_file_where(user_id, path),
).values(
content=content,
created_at=func.now(),
)
)
except IntegrityError as error:
# The file already exists, so overwrite its content with the newer
# version.
if is_unique_violation(error):
savepoint.rollback()
res = db.execute(
files.update().where(
_file_where(user_id, path),
).values(
content=content,
created_at=func.now(),
)
)
else:
# Unknown error. Reraise
raise
else:
# Unknown error. Reraise
raise

return res

Expand Down
2 changes: 1 addition & 1 deletion pgcontents/utils/ipycompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
import IPython

SUPPORTED_VERSIONS = {3, 4, 5}
SUPPORTED_VERSIONS = {3, 4, 5, 6, 7, 8}
IPY_MAJOR = IPython.version_info[0]
if IPY_MAJOR not in SUPPORTED_VERSIONS:
raise ImportError("IPython version %d is not supported." % IPY_MAJOR)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Jinja2>=2.7.3
Mako>=1.0.0
MarkupSafe>=0.23
Pygments>=2.0.1
SQLAlchemy>=1.0.5
SQLAlchemy==1.4.52
alembic>=0.7.6
backports.ssl-match-hostname>=3.4.0.2
certifi>=14.05.14
Expand Down