|
3 | 3 | # pylint: disable=no-member
|
4 | 4 | ########################################################################
|
5 | 5 |
|
| 6 | +# We disable pylint no-callable because of https://github.com/PyCQA/pylint/issues/8138 |
| 7 | + |
6 | 8 | """ Frontend for ReqDB
|
7 | 9 |
|
8 | 10 | :mod: RequestDB
|
|
26 | 28 | import datetime
|
27 | 29 |
|
28 | 30 | 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 |
30 | 32 | from sqlalchemy.sql import update
|
31 | 33 | from sqlalchemy import (
|
32 | 34 | create_engine,
|
|
44 | 46 | distinct,
|
45 | 47 | )
|
46 | 48 |
|
| 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 | + |
47 | 58 | # # from DIRAC
|
48 | 59 | from DIRAC import S_OK, S_ERROR, gLogger
|
49 | 60 | from DIRAC.RequestManagementSystem.Client.Request import Request
|
|
80 | 91 |
|
81 | 92 | # Map the File object to the fileTable, with a few special attributes
|
82 | 93 |
|
83 |
| -mapper( |
| 94 | +sqlalchemy_mapper( |
84 | 95 | File,
|
85 | 96 | fileTable,
|
86 | 97 | properties={
|
|
120 | 131 |
|
121 | 132 | # Map the Operation object to the operationTable, with a few special attributes
|
122 | 133 |
|
123 |
| -mapper( |
| 134 | +sqlalchemy_mapper( |
124 | 135 | Operation,
|
125 | 136 | operationTable,
|
126 | 137 | properties={
|
|
164 | 175 | )
|
165 | 176 |
|
166 | 177 | # Map the Request object to the requestTable, with a few special attributes
|
167 |
| -mapper( |
| 178 | +sqlalchemy_mapper( |
168 | 179 | Request,
|
169 | 180 | requestTable,
|
170 | 181 | properties={
|
@@ -402,7 +413,7 @@ def getRequest(self, reqID=0, assigned=True):
|
402 | 413 | # the joinedload is to force the non-lazy loading of all the attributes, especially _parent
|
403 | 414 | request = (
|
404 | 415 | session.query(Request)
|
405 |
| - .options(joinedload("__operations__").joinedload("__files__")) |
| 416 | + .options(joinedload(Request.__operations__).joinedload(Operation.__files__)) |
406 | 417 | .filter(Request.RequestID == requestID)
|
407 | 418 | .one()
|
408 | 419 | )
|
@@ -467,7 +478,7 @@ def getBulkRequests(self, numberOfRequest=10, assigned=True):
|
467 | 478 |
|
468 | 479 | requests = (
|
469 | 480 | session.query(Request)
|
470 |
| - .options(joinedload("__operations__").joinedload("__files__")) |
| 481 | + .options(joinedload(Request.__operations__).joinedload(Operation.__files__)) |
471 | 482 | .filter(Request.RequestID.in_(requestIDs))
|
472 | 483 | .all()
|
473 | 484 | )
|
@@ -564,21 +575,31 @@ def getDBSummary(self):
|
564 | 575 | session = self.DBSession()
|
565 | 576 |
|
566 | 577 | 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 | + ) |
568 | 583 |
|
569 | 584 | for status, count in requestQuery:
|
570 | 585 | retDict["Request"][status] = count
|
571 | 586 |
|
572 | 587 | 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 | + ) |
574 | 591 | .group_by(Operation.Type, Operation._Status)
|
575 | 592 | .all()
|
576 | 593 | )
|
577 | 594 |
|
578 | 595 | for oType, status, count in operationQuery:
|
579 | 596 | retDict["Operation"].setdefault(oType, {})[status] = count
|
580 | 597 |
|
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 | + ) |
582 | 603 |
|
583 | 604 | for status, count in fileQuery:
|
584 | 605 | retDict["File"][status] = count
|
@@ -726,7 +747,9 @@ def getRequestCountersWeb(self, groupingAttribute, selectDict):
|
726 | 747 | groupingAttribute = "Request.%s" % groupingAttribute
|
727 | 748 |
|
728 | 749 | 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 | + ) |
730 | 753 |
|
731 | 754 | for key, value in selectDict.items():
|
732 | 755 | if key == "ToDate":
|
@@ -840,7 +863,7 @@ def readRequestsForJobs(self, jobIDs=None):
|
840 | 863 | try:
|
841 | 864 | ret = (
|
842 | 865 | session.query(Request.JobID, Request)
|
843 |
| - .options(joinedload("__operations__").joinedload("__files__")) |
| 866 | + .options(joinedload(Request.__operations__).joinedload(Operation.__files__)) |
844 | 867 | .filter(Request.JobID.in_(jobIDs))
|
845 | 868 | .all()
|
846 | 869 | )
|
|
0 commit comments