Skip to content

Commit fd1f120

Browse files
authored
Merge pull request #6741 from chaen/v7r3_FIX_sqlAlchemy2.0
[7r3] fix sql alchemy2.0
2 parents 9635500 + 819c561 commit fd1f120

File tree

17 files changed

+80
-47
lines changed

17 files changed

+80
-47
lines changed

.github/workflows/basic-python3.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
# * `test_BaseType_Unicode` and `test_nestedStructure` fail due to
7171
# DISET's string and unicode types being poorly defined
7272
- pytest --runslow -k 'not test_BaseType_Unicode and not test_nestedStructure'
73-
- pylint -E src/
73+
- pylint -j 0 -E src/
7474

7575
steps:
7676
- uses: actions/checkout@v3

environment-py3.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ channels:
77

88
dependencies:
99
# Temporary workarounds
10-
- astroid 2.5.6 # https://github.com/PyCQA/astroid/issues/1006 and https://github.com/PyCQA/astroid/issues/1007
1110
# runtime
1211
- python =3.9
1312
- pip
@@ -60,7 +59,7 @@ dependencies:
6059
- make
6160
- mock
6261
- parameterized
63-
- pylint >=1.6.5
62+
- pylint
6463
- pyparsing >=2.0.6
6564
- pytest >=3.6
6665
- pytest-cov >=2.2.0

src/DIRAC/ConfigurationSystem/Agent/GOCDB2CSAgent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def execute(self):
5959
for option, functionCall in GOCDB2CSAgent._functionMap.items():
6060
optionValue = self.am_getOption(option, True)
6161
if optionValue:
62-
result = functionCall(self)
62+
result = functionCall(self) # pylint: disable=too-many-function-args
6363
if not result["OK"]:
6464
self.log.error("%s() failed with message: %s" % (functionCall.__name__, result["Message"]))
6565
else:

src/DIRAC/Core/Utilities/Graphs/PlotBase.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
The DIRAC Graphs package is derived from the GraphTool plotting package of the
44
CMS/Phedex Project by ... <to be added>
55
"""
6+
# matplotlib dynamicaly defines all the get_xticklabels and the like,
7+
# so we just ignore it
8+
# pylint: disable=not-callable
69

710
from __future__ import print_function
811
from __future__ import absolute_import

src/DIRAC/Core/Utilities/Graphs/QualityMapGraph.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,10 @@ def draw(self):
172172
self.ax.set_xlim(xmin=start_plot, xmax=end_plot)
173173
else:
174174
self.ax.set_xlim(xmin=min(tmp_x), xmax=max(tmp_x))
175-
self.ax.set_yticks([i + 0.5 for i in range(nLabel)])
176-
self.ax.set_yticklabels(labelNames)
177-
setp(self.ax.get_xticklines(), markersize=0.0)
178-
setp(self.ax.get_yticklines(), markersize=0.0)
175+
self.ax.set_yticks([i + 0.5 for i in range(nLabel)]) # pylint: disable=not-callable
176+
self.ax.set_yticklabels(labelNames) # pylint: disable=not-callable
177+
setp(self.ax.get_xticklines(), markersize=0.0) # pylint: disable=not-callable
178+
setp(self.ax.get_yticklines(), markersize=0.0) # pylint: disable=not-callable
179179

180180
cax, kw = make_axes(self.ax, orientation="vertical", fraction=0.07)
181181
cb = ColorbarBase(

src/DIRAC/Core/Utilities/Pfn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def srm_pfnunparse(pfnDict):
5959
# host:port
6060
uri = "%s:%s" % (pfnDict["Host"], pfnDict["Port"])
6161
if pfnDict["WSUrl"]:
62-
if "?" in pfnDict["WSUrl"] and "=" in pfnDict["WSUrl"]:
62+
if "?" in pfnDict["WSUrl"] and "=" in pfnDict["WSUrl"]: # pylint: disable=unsupported-membership-test
6363
# host/wsurl
6464
# host:port/wsurl
6565
uri = "%s%s" % (uri, pfnDict["WSUrl"])

src/DIRAC/DataManagementSystem/DB/FTS3DB.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from sqlalchemy.orm.exc import NoResultFound
1616
from sqlalchemy.exc import SQLAlchemyError
1717
from sqlalchemy.sql.expression import and_
18-
from sqlalchemy.orm import relationship, sessionmaker, mapper
18+
from sqlalchemy.orm import relationship, sessionmaker
1919
from sqlalchemy.sql import update, delete
2020
from sqlalchemy import (
2121
create_engine,
@@ -34,6 +34,15 @@
3434
text,
3535
)
3636

37+
try:
38+
from sqlalchemy.orm import registry
39+
40+
sqlalchemy_mapper = registry().map_imperatively
41+
except ImportError: # registry appeared in sqlalchemy 2.0
42+
from sqlalchemy.orm import mapper
43+
44+
sqlalchemy_mapper = mapper
45+
3746
# # from DIRAC
3847
from DIRAC import S_OK, S_ERROR, gLogger
3948
from DIRAC.DataManagementSystem.Client.FTS3Operation import FTS3Operation, FTS3TransferOperation, FTS3StagingOperation
@@ -69,7 +78,7 @@
6978
mysql_engine="InnoDB",
7079
)
7180

72-
mapper(FTS3File, fts3FileTable)
81+
sqlalchemy_mapper(FTS3File, fts3FileTable)
7382

7483

7584
fts3JobTable = Table(
@@ -93,7 +102,7 @@
93102
mysql_engine="InnoDB",
94103
)
95104

96-
mapper(FTS3Job, fts3JobTable)
105+
sqlalchemy_mapper(FTS3Job, fts3JobTable)
97106

98107

99108
fts3OperationTable = Table(
@@ -119,7 +128,7 @@
119128
)
120129

121130

122-
fts3Operation_mapper = mapper(
131+
fts3Operation_mapper = sqlalchemy_mapper(
123132
FTS3Operation,
124133
fts3OperationTable,
125134
properties={
@@ -146,9 +155,13 @@
146155
polymorphic_identity="Abs",
147156
)
148157

149-
mapper(FTS3TransferOperation, fts3OperationTable, inherits=fts3Operation_mapper, polymorphic_identity="Transfer")
158+
sqlalchemy_mapper(
159+
FTS3TransferOperation, fts3OperationTable, inherits=fts3Operation_mapper, polymorphic_identity="Transfer"
160+
)
150161

151-
mapper(FTS3StagingOperation, fts3OperationTable, inherits=fts3Operation_mapper, polymorphic_identity="Staging")
162+
sqlalchemy_mapper(
163+
FTS3StagingOperation, fts3OperationTable, inherits=fts3Operation_mapper, polymorphic_identity="Staging"
164+
)
152165

153166

154167
# About synchronize_session:

src/DIRAC/MonitoringSystem/DB/MonitoringDB.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def retrieveBucketedData(
214214
continue
215215
kwargs = {cond: condValue}
216216
if query:
217-
query = query | self._Q("term", **kwargs)
217+
query = query | self._Q("term", **kwargs) # pylint: disable=unsupported-binary-operation
218218
else:
219219
query = self._Q("term", **kwargs)
220220
if query:
@@ -349,7 +349,7 @@ def retrieveAggregatedData(
349349
continue
350350
kwargs = {cond: condValue}
351351
if query:
352-
query = query | self._Q("term", **kwargs)
352+
query = query | self._Q("term", **kwargs) # pylint: disable=unsupported-binary-operation
353353
else:
354354
query = self._Q("term", **kwargs)
355355
if query:

src/DIRAC/RequestManagementSystem/DB/RequestDB.py

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# pylint: disable=no-member
44
########################################################################
55

6+
# We disable pylint no-callable because of https://github.com/PyCQA/pylint/issues/8138
7+
68
""" Frontend for ReqDB
79
810
:mod: RequestDB
@@ -26,7 +28,7 @@
2628
import datetime
2729

2830
from sqlalchemy.orm.exc import NoResultFound
29-
from sqlalchemy.orm import relationship, backref, sessionmaker, joinedload, mapper
31+
from sqlalchemy.orm import relationship, backref, sessionmaker, joinedload
3032
from sqlalchemy.sql import update
3133
from sqlalchemy import (
3234
create_engine,
@@ -44,6 +46,15 @@
4446
distinct,
4547
)
4648

49+
try:
50+
from sqlalchemy.orm import registry
51+
52+
sqlalchemy_mapper = registry().map_imperatively
53+
except ImportError: # registry appeared in sqlalchemy 2.0
54+
from sqlalchemy.orm import mapper
55+
56+
sqlalchemy_mapper = mapper
57+
4758
# # from DIRAC
4859
from DIRAC import S_OK, S_ERROR, gLogger
4960
from DIRAC.RequestManagementSystem.Client.Request import Request
@@ -80,7 +91,7 @@
8091

8192
# Map the File object to the fileTable, with a few special attributes
8293

83-
mapper(
94+
sqlalchemy_mapper(
8495
File,
8596
fileTable,
8697
properties={
@@ -120,7 +131,7 @@
120131

121132
# Map the Operation object to the operationTable, with a few special attributes
122133

123-
mapper(
134+
sqlalchemy_mapper(
124135
Operation,
125136
operationTable,
126137
properties={
@@ -164,7 +175,7 @@
164175
)
165176

166177
# Map the Request object to the requestTable, with a few special attributes
167-
mapper(
178+
sqlalchemy_mapper(
168179
Request,
169180
requestTable,
170181
properties={
@@ -402,7 +413,7 @@ def getRequest(self, reqID=0, assigned=True):
402413
# the joinedload is to force the non-lazy loading of all the attributes, especially _parent
403414
request = (
404415
session.query(Request)
405-
.options(joinedload("__operations__").joinedload("__files__"))
416+
.options(joinedload(Request.__operations__).joinedload(Operation.__files__))
406417
.filter(Request.RequestID == requestID)
407418
.one()
408419
)
@@ -467,7 +478,7 @@ def getBulkRequests(self, numberOfRequest=10, assigned=True):
467478

468479
requests = (
469480
session.query(Request)
470-
.options(joinedload("__operations__").joinedload("__files__"))
481+
.options(joinedload(Request.__operations__).joinedload(Operation.__files__))
471482
.filter(Request.RequestID.in_(requestIDs))
472483
.all()
473484
)
@@ -564,21 +575,31 @@ def getDBSummary(self):
564575
session = self.DBSession()
565576

566577
try:
567-
requestQuery = session.query(Request._Status, func.count(Request.RequestID)).group_by(Request._Status).all()
578+
requestQuery = (
579+
session.query(Request._Status, func.count(Request.RequestID)) # pylint: disable=not-callable
580+
.group_by(Request._Status)
581+
.all()
582+
)
568583

569584
for status, count in requestQuery:
570585
retDict["Request"][status] = count
571586

572587
operationQuery = (
573-
session.query(Operation.Type, Operation._Status, func.count(Operation.OperationID))
588+
session.query(
589+
Operation.Type, Operation._Status, func.count(Operation.OperationID) # pylint: disable=not-callable
590+
)
574591
.group_by(Operation.Type, Operation._Status)
575592
.all()
576593
)
577594

578595
for oType, status, count in operationQuery:
579596
retDict["Operation"].setdefault(oType, {})[status] = count
580597

581-
fileQuery = session.query(File._Status, func.count(File.FileID)).group_by(File._Status).all()
598+
fileQuery = (
599+
session.query(File._Status, func.count(File.FileID)) # pylint: disable=not-callable
600+
.group_by(File._Status)
601+
.all()
602+
)
582603

583604
for status, count in fileQuery:
584605
retDict["File"][status] = count
@@ -726,7 +747,9 @@ def getRequestCountersWeb(self, groupingAttribute, selectDict):
726747
groupingAttribute = "Request.%s" % groupingAttribute
727748

728749
try:
729-
summaryQuery = session.query(eval(groupingAttribute), func.count(Request.RequestID))
750+
summaryQuery = session.query(
751+
eval(groupingAttribute), func.count(Request.RequestID) # pylint: disable=not-callable
752+
)
730753

731754
for key, value in selectDict.items():
732755
if key == "ToDate":
@@ -840,7 +863,7 @@ def readRequestsForJobs(self, jobIDs=None):
840863
try:
841864
ret = (
842865
session.query(Request.JobID, Request)
843-
.options(joinedload("__operations__").joinedload("__files__"))
866+
.options(joinedload(Request.__operations__).joinedload(Operation.__files__))
844867
.filter(Request.JobID.in_(jobIDs))
845868
.all()
846869
)

src/DIRAC/ResourceStatusSystem/Command/test/Test_RSS_Command_VOBOXAvailabilityCommand.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
try:
1717
# Python 2: "reload" is built-in
18-
reload
18+
reload # pylint: disable=used-before-assignment
1919
except NameError:
2020
from importlib import reload # pylint: disable=no-name-in-module
2121

0 commit comments

Comments
 (0)