Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Mentat Test 3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
713
Mentat
Mentat Test 3
Commits
87b875d2
Commit
87b875d2
authored
1 year ago
by
Jakub Judiny
Browse files
Options
Downloads
Patches
Plain Diff
Replace flask-sqlalchemy with sqlalchemy in sqlstorage.py, upgrade both
(Redmine issue: #7642)
parent
02cbe2ab
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
conf/requirements.pip
+2
-2
2 additions, 2 deletions
conf/requirements.pip
lib/mentat/services/sqlstorage.py
+8
-15
8 additions, 15 deletions
lib/mentat/services/sqlstorage.py
with
10 additions
and
17 deletions
conf/requirements.pip
+
2
−
2
View file @
87b875d2
...
...
@@ -3,7 +3,7 @@ psycopg2>=2.9.6,<2.10.0
babel>=2.12.1,<2.13.0
wtforms[email]>=3.0.1,<4.0.0
wtforms_sqlalchemy>=0.3,<1.0.0
sqlalchemy>=
1.4.47,<2
.0.0
sqlalchemy>=
2.0.12,<=3
.0.0
alembic>=1.10.2,<2.0.0
jinja2>=3.1.2,<3.2.0
bsddb3>=6.2.9,<6.3.0
...
...
@@ -16,7 +16,7 @@ flask-babel>=3.0.1,<4.0.0
flask-principal>=0.4.0,<1.0.0
flask-wtf>=1.1.1,<2.0.0
flask-script>=2.0.6,<3.0.0
flask-sqlalchemy>=
2.5.1
,<
3
.0.0
flask-sqlalchemy>=
3.0.3
,<
4
.0.0
flask-debugtoolbar>=0.13.1,<1.0.0
flask-jsglue>=0.3.1,<1.0.0
dnspython>=2.3.0,<3.0.0
...
...
This diff is collapsed.
Click to expand it.
lib/mentat/services/sqlstorage.py
+
8
−
15
View file @
87b875d2
...
...
@@ -10,8 +10,7 @@
"""
Database storage abstraction layer. The current implementation is based on the
awesome `SQLAlchemy <http://www.sqlalchemy.org/>`__ library accessed by
`flask_sqlalchemy <https://flask-sqlalchemy.palletsprojects.com/>`__.
awesome `SQLAlchemy <http://www.sqlalchemy.org/>`__ library.
.. warning::
...
...
@@ -27,8 +26,7 @@ __credits__ = "Pavel Kácha <pavel.kacha@cesnet.cz>, Andrea Kropáčová <andrea
import
copy
from
flask
import
Flask
import
flask_sqlalchemy
import
sqlalchemy
#
# Custom libraries
...
...
@@ -40,7 +38,7 @@ from mentat.datatype.sqldb import MODEL
_MANAGER
=
None
class
RetryingQuery
(
flask_
sqlalchemy
.
orm
.
Query
):
class
RetryingQuery
(
sqlalchemy
.
orm
.
Query
):
"""
An override of SQLAlchemy
'
s Query class, allowing for recovery from a lost DB
connection.
...
...
@@ -49,7 +47,7 @@ class RetryingQuery(flask_sqlalchemy.orm.Query):
for
_
in
range
(
2
):
try
:
return
super
().
_execute_and_instances
(
querycontext
)
except
flask_
sqlalchemy
.
orm
.
exc
.
sa_
exc
.
OperationalError
:
except
sqlalchemy
.
exc
.
OperationalError
:
self
.
session
.
close
()
continue
...
...
@@ -68,14 +66,9 @@ class StorageService:
:param enginecfg: Connection arguments.
"""
self
.
app
=
Flask
(
__name__
)
self
.
app
.
config
[
'
SQLALCHEMY_DATABASE_URI
'
]
=
enginecfg
[
'
url
'
]
self
.
app
.
config
[
'
SQLALCHEMY_TRACK_MODIFICATIONS
'
]
=
False
self
.
db
=
flask_sqlalchemy
.
SQLAlchemy
(
self
.
app
)
self
.
dbengine
=
self
.
db
.
engine_from_config
(
enginecfg
,
prefix
=
''
)
self
.
sessionmaker
=
flask_sqlalchemy
.
orm
.
sessionmaker
(
bind
=
self
.
dbengine
)
self
.
_session
=
self
.
sessionmaker
(
query_cls
=
RetryingQuery
)
self
.
dbengine
=
sqlalchemy
.
engine_from_config
(
enginecfg
,
prefix
=
''
)
self
.
sessionmaker
=
sqlalchemy
.
orm
.
scoped_session
(
sqlalchemy
.
orm
.
sessionmaker
(
bind
=
self
.
dbengine
))
self
.
_session
=
self
.
sessionmaker
(
query_cls
=
RetryingQuery
)
def
__del__
(
self
):
self
.
close
()
...
...
@@ -101,7 +94,7 @@ class StorageService:
"""
if
self
.
_session
:
self
.
_
session
.
clos
e
()
self
.
session
maker
.
remov
e
()
self
.
_session
=
None
def
session_new
(
self
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment