tacker/tacker/db
Manpreet Kaur e0c09499a6 Fix migration for SQLAlchemy 1.4
This patch fixes a database migration for SQLAlchemy 1.4.

In tacker repository following issues are encounter:

1. Replace deprecated SQLAlchemy "with_lockmode" method.
   The method was deprecated in SQLAlchemy 0.9 [1][2]
   and finally removed in version 1.4.
   This patch replaces "with_lockmode" with new method
   "with_for_update", which has no end-user impact.

2. The clause column IN, in the new version it requires parameters
   passed to operator either be a list of literal value
   or a tuple, or an empty list [3].

3. Observe an argument error in 'update' query.
   Error: sqlalchemy.exc.ArgumentError: subject table for an INSERT,
   UPDATE or DELETE expected, got Column('id', Uuid(length=36),
   table=<vnf_software_images>, primary_key=True, nullable=False,
   default=ColumnDefault(<function generate_uuid at 0x7fb5be371d30>))

4. The INSERT statement requires values to add in table as a list,
   tuple or dictionary [4].
   Error: sqlalchemy.exc.ArgumentError: mapping or sequence expected
          for parameters
   This patch creates a dictionary of fields to be insert in
   VnfLcmOpOccs table.

5. Query fails on applying filters.
   When applying query to list vnf package or vnf instance using
   apply_filters() method exported from sqlalchemy_filters,
   it failed.
   AttributeError: 'Query' object has no attribute '_join_entities'

   In SQLAlchemy 1.4 unification of "query" and "select" construct
   took place [5][6].
   The issue observe in tacker is an open bug of SQLAlchemy [7].
   This patch drops "sqlalchemy_filters" and add customize method
   to apply filters in query.

Note: This patch address sqlalchemy errors, SAWarnings will be resolve
in future patches.

[1] https://docs.sqlalchemy.org/en/13/changelog/migration_09.html?highlight=with_lockmode#new-for-update-support-on-select-query
[2] https://docs.sqlalchemy.org/en/13/orm/query.html#sqlalchemy.orm.query.Query.with_lockmode
[3] https://docs.sqlalchemy.org/en/14/core/sqlelement.html#sqlalchemy.sql.expression.ColumnElement.in_
[4] https://docs.sqlalchemy.org/en/14/core/dml.html#dml-class-documentation-constructors
[5] https://github.com/sqlalchemy/sqlalchemy/issues/5159
[6] https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/1599/
[7] https://github.com/juliotrigo/sqlalchemy-filters/issues/61

Co-Authored-By: Ayumu Ueha <ueha.ayumu@fujitsu.com>

Change-Id: Ifd1ae2753c639f22fc1afa020222416fe79469ef
2021-07-10 06:50:43 +05:30
..
common_services FIX: nfv event list failed with internal server error 2019-06-28 11:13:45 +00:00
db_sqlalchemy Support enhancement for Get Subscription List 2021-03-26 20:19:31 +09:00
migration Support enhancement for Subscription Post 2021-03-26 19:54:35 +09:00
nfvo Fix migration for SQLAlchemy 1.4 2021-07-10 06:50:43 +05:30
vnfm Fix migration for SQLAlchemy 1.4 2021-07-10 06:50:43 +05:30
__init__.py rename neutron/db to tacker/db 2014-07-04 18:20:50 +09:00
api.py Remove unused LOG to keep code clean 2016-07-09 16:21:47 +08:00
db_base.py Fix migration for SQLAlchemy 1.4 2021-07-10 06:50:43 +05:30
model_base.py Use oslo db for db access 2016-06-07 12:09:57 +08:00
models_v1.py Enables soft deletion for VIM, VNFD and VNF 2016-08-20 04:23:30 +00:00
sqlalchemyutils.py Drop most of six importings 2020-10-19 12:10:05 +00:00
types.py Update json module to jsonutils 2019-02-27 11:59:02 +00:00