Skip to content

Commit

Permalink
QueryBuilder: Catch new exception raised by sqlalchemy>=1.4.45 (a…
Browse files Browse the repository at this point in the history
…iidateam#5875)

As of `sqlalchemy==1.4.45` the `SQLCompiler.render_literal_value` method
started raising a `CompileError` instead of `NotImplementedError`. This
is now explicitly caught to provide support for older and newer versions.
  • Loading branch information
ltalirz authored Jan 27, 2023
1 parent 76b6ba5 commit c1d99df
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions aiida/storage/psql_dos/orm/querybuilder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from sqlalchemy import not_, or_
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.engine import Row
from sqlalchemy.exc import SAWarning
from sqlalchemy.exc import CompileError, SAWarning
from sqlalchemy.orm import aliased
from sqlalchemy.orm.attributes import InstrumentedAttribute, QueryableAttribute
from sqlalchemy.orm.query import Query
Expand Down Expand Up @@ -889,7 +889,8 @@ def render_literal_value(self, value, type_):

try:
return super().render_literal_value(value, type_)
except NotImplementedError:
# sqlalchemy<1.4.45 raises NotImplementedError, sqlalchemy>=1.4.45 raises CompileError
except (NotImplementedError, CompileError):
if isinstance(value, list):
values = ','.join(self.render_literal_value(item, type_) for item in value)
return f"'[{values}]'"
Expand Down

0 comments on commit c1d99df

Please sign in to comment.