Fixed code smell 'Functions, methods, and lambdas should not have too many parameters' reported by SonarQube.

This commit is contained in:
Akshay Joshi 2020-07-07 19:39:06 +05:30
parent 36a2c073bd
commit b4c25bdc0a
12 changed files with 184 additions and 148 deletions

View File

@ -597,7 +597,7 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings,
return gone(gettext("The specified table could not be found."))
return super(TableView, self).properties(
gid, sid, did, scid, tid, res
gid, sid, did, scid, tid, res=res
)
def _fetch_properties(self, did, scid, tid):
@ -1082,7 +1082,7 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings,
return res
return super(TableView, self).update(
gid, sid, did, scid, tid, data, res)
gid, sid, did, scid, tid, data=data, res=res)
except Exception as e:
return internal_server_error(errormsg=str(e))
@ -1282,7 +1282,8 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings,
data['schema'] = diff_schema
sql, partition_sql = BaseTableView.get_reverse_engineered_sql(
self, did, scid, tid, main_sql, data, json_resp)
self, did=did, scid=scid, tid=tid, main_sql=main_sql,
data=data, json_resp=json_resp)
return sql
@ -1390,7 +1391,7 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings,
data = res['rows'][0]
return BaseTableView.get_reverse_engineered_sql(
self, did, scid, tid, main_sql, data)
self, did=did, scid=scid, tid=tid, main_sql=main_sql, data=data)
@BaseTableView.check_precondition
def select_sql(self, gid, sid, did, scid, tid):
@ -1682,7 +1683,7 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings,
return False
data = super(TableView, self).properties(
0, sid, did, scid, tid, data, False
0, sid, did, scid, tid, res=data, return_ajax_response=False
)
return data
@ -1701,7 +1702,8 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings,
if status:
data = super(TableView, self).properties(
0, sid, did, scid, row['oid'], data, False
0, sid, did, scid, row['oid'], res=data,
return_ajax_response=False
)
# Get sub module data of a specified table for object

View File

@ -751,8 +751,8 @@ class CompoundTriggerView(PGChildNodeView, SchemaDiffObjectCompare):
"""
try:
SQL = compound_trigger_utils.get_reverse_engineered_sql(
self.conn, self.schema, self.table, tid, trid,
self.datlastsysoid)
self.conn, schema=self.schema, table=self.table, tid=tid,
trid=trid, datlastsysoid=self.datlastsysoid)
except Exception as e:
return internal_server_error(errormsg=str(e))

View File

@ -143,19 +143,20 @@ def get_sql(conn, data, tid, trid, datlastsysoid, template_path=None):
@get_template_path
def get_reverse_engineered_sql(conn, schema, table, tid, trid,
datlastsysoid, template_path=None):
def get_reverse_engineered_sql(conn, **kwargs):
"""
This function will return reverse engineered sql for trigger(s).
:param conn: Connection Object
:param schema: Schema
:param table: Table
:param tid: Table ID
:param trid: Trigger ID
:param datlastsysoid:
:param template_path: Optional template path
:param kwargs
:return:
"""
schema = kwargs.get('schema')
table = kwargs.get('table')
tid = kwargs.get('tid')
trid = kwargs.get('trid')
datlastsysoid = kwargs.get('datlastsysoid')
template_path = kwargs.get('template_path', None)
SQL = render_template("/".join([template_path, 'properties.sql']),
tid=tid, trid=trid,
datlastsysoid=datlastsysoid)

View File

@ -745,7 +745,8 @@ class IndexesView(PGChildNodeView, SchemaDiffObjectCompare):
data['table'] = self.table
try:
SQL, name = index_utils.get_sql(
self.conn, data, did, tid, idx, self.datlastsysoid)
self.conn, data=data, did=did, tid=tid, idx=idx,
datlastsysoid=self.datlastsysoid)
if not isinstance(SQL, str):
return SQL
SQL = SQL.strip('\n').strip(' ')
@ -795,8 +796,8 @@ class IndexesView(PGChildNodeView, SchemaDiffObjectCompare):
try:
sql, name = index_utils.get_sql(
self.conn, data, did, tid, idx, self.datlastsysoid,
mode='create')
self.conn, data=data, did=did, tid=tid, idx=idx,
datlastsysoid=self.datlastsysoid, mode='create')
if not isinstance(sql, str):
return sql
sql = sql.strip('\n').strip(' ')
@ -824,24 +825,36 @@ class IndexesView(PGChildNodeView, SchemaDiffObjectCompare):
"""
SQL = index_utils.get_reverse_engineered_sql(
self.conn, self.schema, self.table, did, tid, idx,
self.datlastsysoid)
self.conn, schema=self.schema, table=self.table, did=did,
tid=tid, idx=idx, datlastsysoid=self.datlastsysoid)
return ajax_response(response=SQL)
@check_precondition
def get_sql_from_index_diff(self, sid, did, scid, tid, idx, data=None,
diff_schema=None, drop_req=False):
def get_sql_from_index_diff(self, **kwargs):
"""
This function get the sql from index diff.
:param kwargs:
:return:
"""
sid = kwargs.get('sid')
did = kwargs.get('did')
scid = kwargs.get('scid')
tid = kwargs.get('tid')
idx = kwargs.get('idx')
data = kwargs.get('data', None)
diff_schema = kwargs.get('diff_schema', None)
drop_req = kwargs.get('drop_req', False)
sql = ''
if data:
data['schema'] = self.schema
data['nspname'] = self.schema
data['table'] = self.table
sql, name = index_utils.get_sql(
self.conn, data, did, tid, idx, self.datlastsysoid,
mode='create')
self.conn, data=data, did=did, tid=tid, idx=idx,
datlastsysoid=self.datlastsysoid, mode='create')
sql = sql.strip('\n').strip(' ')

View File

@ -193,21 +193,23 @@ def _get_sql_with_index_none(data, template_path, conn, mode, name):
@get_template_path
def get_sql(conn, data, did, tid, idx, datlastsysoid,
mode=None, template_path=None):
def get_sql(conn, **kwargs):
"""
This function will generate sql from model data.
:param conn: Connection Object
:param data: Data
:param did:
:param tid: Table ID
:param idx: Index ID
:param datlastsysoid:
:param mode:
:param template_path: Optional template path
:param kwargs:
:return:
"""
data = kwargs.get('data')
did = kwargs.get('did')
tid = kwargs.get('tid')
idx = kwargs.get('idx')
datlastsysoid = kwargs.get('datlastsysoid')
mode = kwargs.get('mode', None)
template_path = kwargs.get('template_path', None)
name = data['name'] if 'name' in data else None
if idx is not None:
sql = render_template("/".join([template_path, 'properties.sql']),
@ -249,23 +251,23 @@ def get_sql(conn, data, did, tid, idx, datlastsysoid,
@get_template_path
def get_reverse_engineered_sql(conn, schema, table, did, tid, idx,
datlastsysoid,
template_path=None, with_header=True):
def get_reverse_engineered_sql(conn, **kwargs):
"""
This function will return reverse engineered sql for specified trigger.
:param conn: Connection Object
:param schema: Schema
:param table: Table
:param tid: Table ID
:param idx: Index ID
:param datlastsysoid:
:param template_path: Optional template path
:param with_header: Optional parameter to decide whether the SQL will be
returned with header or not
:param kwargs:
:return:
"""
schema = kwargs.get('schema')
table = kwargs.get('table')
did = kwargs.get('did')
tid = kwargs.get('tid')
idx = kwargs.get('idx')
datlastsysoid = kwargs.get('datlastsysoid')
template_path = kwargs.get('template_path', None)
with_header = kwargs.get('with_header', True)
SQL = render_template("/".join([template_path, 'properties.sql']),
did=did, tid=tid, idx=idx,
datlastsysoid=datlastsysoid)
@ -289,7 +291,8 @@ def get_reverse_engineered_sql(conn, schema, table, did, tid, idx,
if conn.manager.version >= 110000:
data = get_include_details(conn, idx, data)
SQL, name = get_sql(conn, data, did, tid, None, datlastsysoid)
SQL, name = get_sql(conn, data=data, did=did, tid=tid, idx=None,
datlastsysoid=datlastsysoid)
if with_header:
sql_header = u"-- Index: {0}\n\n-- ".format(data['name'])

View File

@ -458,8 +458,8 @@ class PartitionsView(BaseTableView, DataTypeReader, VacuumSettings,
data = res['rows'][0]
return BaseTableView.get_reverse_engineered_sql(self, did, scid, ptid,
main_sql, data)
return BaseTableView.get_reverse_engineered_sql(
self, did=did, scid=scid, tid=ptid, main_sql=main_sql, data=data)
@BaseTableView.check_precondition
def get_sql_from_diff(self, **kwargs):

View File

@ -64,13 +64,16 @@ class SchemaDiffTableCompare(SchemaDiffObjectCompare):
len(source_tables) <= 0 and len(target_tables) <= 0):
return None
return compare_dictionaries(self, source_params, target_params,
target_schema, source_tables,
target_tables,
self.node_type,
self.blueprint.COLLECTION_LABEL,
ignore_whitespaces,
self.keys_to_ignore)
return compare_dictionaries(view_object=self,
source_params=source_params,
target_params=target_params,
target_schema=target_schema,
source_dict=source_tables,
target_dict=target_tables,
node=self.node_type,
node_label=self.blueprint.COLLECTION_LABEL,
ignore_whitespaces=ignore_whitespaces,
ignore_keys=self.keys_to_ignore)
def ddl_compare(self, **kwargs):
"""
@ -226,22 +229,22 @@ class SchemaDiffTableCompare(SchemaDiffObjectCompare):
return different
def get_sql_from_submodule_diff(self, source_params, target_params,
target_schema, source, target, diff_dict,
ignore_whitespaces):
def get_sql_from_submodule_diff(self, **kwargs):
"""
This function returns the DDL/DML statements of the
submodules of table based on the comparison status.
:param source_params:
:param target_params:
:param target_schema:
:param source:
:param target:
:param diff_dict:
:param ignore_whitespaces:
:param kwargs:
:return:
"""
source_params = kwargs.get('source_params')
target_params = kwargs.get('target_params')
target_schema = kwargs.get('target_schema')
source = kwargs.get('source')
target = kwargs.get('target')
diff_dict = kwargs.get('diff_dict')
ignore_whitespaces = kwargs.get('ignore_whitespaces')
# Get the difference result for source and target columns
col_diff = self.table_col_comp(source, target)
diff_dict.update(col_diff)

View File

@ -672,8 +672,9 @@ class TriggerView(PGChildNodeView, SchemaDiffObjectCompare):
data['table'] = self.table
SQL, name = trigger_utils.get_sql(
self.conn, data, tid, trid, self.datlastsysoid,
self.blueprint.show_system_objects)
self.conn, data=data, tid=tid, trid=trid,
datlastsysoid=self.datlastsysoid,
show_system_objects=self.blueprint.show_system_objects)
if not isinstance(SQL, str):
return SQL
@ -754,8 +755,9 @@ class TriggerView(PGChildNodeView, SchemaDiffObjectCompare):
try:
sql, name = trigger_utils.get_sql(
self.conn, data, tid, trid, self.datlastsysoid,
self.blueprint.show_system_objects)
self.conn, data=data, tid=tid, trid=trid,
datlastsysoid=self.datlastsysoid,
show_system_objects=self.blueprint.show_system_objects)
if not isinstance(sql, str):
return sql
sql = sql.strip('\n').strip(' ')
@ -784,8 +786,9 @@ class TriggerView(PGChildNodeView, SchemaDiffObjectCompare):
"""
SQL = trigger_utils.get_reverse_engineered_sql(
self.conn, self.schema, self.table, tid, trid,
self.datlastsysoid, self.blueprint.show_system_objects)
self.conn, schema=self.schema, table=self.table, tid=tid,
trid=trid, datlastsysoid=self.datlastsysoid,
show_system_objects=self.blueprint.show_system_objects)
return ajax_response(response=SQL)
@ -808,9 +811,10 @@ class TriggerView(PGChildNodeView, SchemaDiffObjectCompare):
if data:
SQL, name = trigger_utils.get_sql(
self.conn, data, tid, oid,
self.datlastsysoid,
self.blueprint.show_system_objects, True)
self.conn, data=data, tid=tid, trid=oid,
datlastsysoid=self.datlastsysoid,
show_system_objects=self.blueprint.show_system_objects,
is_schema_diff=True)
if not isinstance(SQL, str):
return SQL
@ -825,10 +829,9 @@ class TriggerView(PGChildNodeView, SchemaDiffObjectCompare):
if diff_schema:
schema = diff_schema
SQL = trigger_utils.get_reverse_engineered_sql(
self.conn, schema,
self.table, tid, oid,
self.datlastsysoid,
self.blueprint.show_system_objects,
self.conn, schema=schema, table=self.table, tid=tid,
trid=oid, datlastsysoid=self.datlastsysoid,
show_system_objects=self.blueprint.show_system_objects,
template_path=None, with_header=False)
return SQL

View File

@ -140,21 +140,22 @@ def get_trigger_function_and_columns(conn, data, tid,
@get_template_path
def get_sql(conn, data, tid, trid, datlastsysoid,
show_system_objects, is_schema_diff=False, template_path=None):
def get_sql(conn, **kwargs):
"""
This function will generate sql from model data.
:param conn: Connection Object
:param data: Data
:param tid: Table ID
:param trid: Trigger ID
:param datlastsysoid:
:param show_system_objects: Show System Object value True or False
:param is_schema_diff:
:param template_path: Optional template path
:param kwargs
:return:
"""
data = kwargs.get('data')
tid = kwargs.get('tid')
trid = kwargs.get('trid')
datlastsysoid = kwargs.get('datlastsysoid')
show_system_objects = kwargs.get('show_system_objects')
is_schema_diff = kwargs.get('is_schema_diff', False)
template_path = kwargs.get('template_path', None)
name = data['name'] if 'name' in data else None
if trid is not None:
sql = render_template("/".join([template_path, 'properties.sql']),
@ -232,24 +233,23 @@ def get_sql(conn, data, tid, trid, datlastsysoid,
@get_template_path
def get_reverse_engineered_sql(conn, schema, table, tid, trid,
datlastsysoid, show_system_objects,
template_path=None, with_header=True):
def get_reverse_engineered_sql(conn, **kwargs):
"""
This function will return reverse engineered sql for specified trigger.
:param conn: Connection Object
:param schema: Schema
:param table: Table
:param tid: Table ID
:param trid: Trigger ID
:param datlastsysoid:
:param show_system_objects: Show System Object value True or False
:param template_path: Optional template path
:param with_header: Optional parameter to decide whether the SQL will be
returned with header or not
:param kwargs:
:return:
"""
schema = kwargs.get('schema')
table = kwargs.get('table')
tid = kwargs.get('tid')
trid = kwargs.get('trid')
datlastsysoid = kwargs.get('datlastsysoid')
show_system_objects = kwargs.get('show_system_objects')
template_path = kwargs.get('template_path', None)
with_header = kwargs.get('with_header', True)
SQL = render_template("/".join([template_path, 'properties.sql']),
tid=tid, trid=trid,
datlastsysoid=datlastsysoid)
@ -272,8 +272,9 @@ def get_reverse_engineered_sql(conn, schema, table, tid, trid,
data = trigger_definition(data)
SQL, name = get_sql(conn, data, tid, None, datlastsysoid,
show_system_objects)
SQL, name = get_sql(conn, data=data, tid=tid, trid=None,
datlastsysoid=datlastsysoid,
show_system_objects=show_system_objects)
if with_header:
sql_header = u"-- Trigger: {0}\n\n-- ".format(data['name'])

View File

@ -414,22 +414,22 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
status=200
)
def get_reverse_engineered_sql(self, did, scid, tid, main_sql, data,
json_resp=True, diff_partition_sql=False):
def get_reverse_engineered_sql(self, **kwargs):
"""
This function will creates reverse engineered sql for
the table object
Args:
did: Database ID
scid: Schema ID
tid: Table ID
main_sql: List contains all the reversed engineered sql
data: Table's Data
json_resp: Json response or plain SQL
diff_partition_sql: In Schema diff, the Partition sql should be
return separately to perform further task
kwargs
"""
did = kwargs.get('did')
scid = kwargs.get('scid')
tid = kwargs.get('tid')
main_sql = kwargs.get('main_sql')
data = kwargs.get('data')
json_resp = kwargs.get('json_resp', True)
diff_partition_sql = kwargs.get('diff_partition_sql', False)
"""
#####################################
# 1) Reverse engineered sql for TABLE
@ -508,8 +508,8 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
tables.indexes import utils as index_utils
for row in rset['rows']:
index_sql = index_utils.get_reverse_engineered_sql(
self.conn, schema, table, did, tid, row['oid'],
self.datlastsysoid,
self.conn, schema=schema, table=table, did=did, tid=tid,
idx=row['oid'], datlastsysoid=self.datlastsysoid,
template_path=None, with_header=json_resp)
index_sql = u"\n" + index_sql
@ -533,10 +533,10 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
return internal_server_error(errormsg=rset)
for row in rset['rows']:
policy_sql = row_security_policies_utils. \
policy_sql = row_security_policies_utils.\
get_reverse_engineered_sql(
self.conn, schema, table, did, scid, tid, row['oid'],
self.datlastsysoid,
self.conn, schema=schema, table=table, scid=scid,
plid=row['oid'], datlastsysoid=self.datlastsysoid,
template_path=None, with_header=json_resp)
policy_sql = u"\n" + policy_sql
@ -558,8 +558,9 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
for row in rset['rows']:
trigger_sql = trigger_utils.get_reverse_engineered_sql(
self.conn, schema, table, tid, row['oid'],
self.datlastsysoid, self.blueprint.show_system_objects,
self.conn, schema=schema, table=table, tid=tid,
trid=row['oid'], datlastsysoid=self.datlastsysoid,
show_system_objects=self.blueprint.show_system_objects,
template_path=None, with_header=json_resp)
trigger_sql = u"\n" + trigger_sql
@ -585,8 +586,8 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
for row in rset['rows']:
compound_trigger_sql = \
compound_trigger_utils.get_reverse_engineered_sql(
self.conn, schema, table, tid, row['oid'],
self.datlastsysoid)
self.conn, schema=schema, table=table, tid=tid,
trid=row['oid'], datlastsysoid=self.datlastsysoid)
compound_trigger_sql = u"\n" + compound_trigger_sql
# Add into main sql
@ -1084,7 +1085,7 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
return SQL, data['name'] if 'name' in data else old_data['name']
def update(self, gid, sid, did, scid, tid, data, res, parent_id=None):
def update(self, gid, sid, did, scid, tid, **kwargs):
"""
This function will update an existing table object
@ -1099,6 +1100,10 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
parent_id: parent table id if current table is partition of parent
table else none
"""
data = kwargs.get('data')
res = kwargs.get('res')
parent_id = kwargs.get('parent_id', None)
# checking the table existence using the function of the same class
schema_name, table_name = self.get_schema_and_table_name(tid)
@ -1221,8 +1226,7 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
except Exception as e:
return internal_server_error(errormsg=str(e))
def properties(self, gid, sid, did, scid, tid, res,
return_ajax_response=True):
def properties(self, gid, sid, did, scid, tid, **kwargs):
"""
This function will show the properties of the selected table node.
@ -1233,12 +1237,13 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
scid: Schema ID
scid: Schema ID
tid: Table ID
res: Table/Partition table properties
return_ajax_response: If True then return the ajax response
Returns:
JSON of selected table node
"""
res = kwargs.get('res')
return_ajax_response = kwargs.get('return_ajax_response', True)
data = res['rows'][0]
data['vacuum_settings_str'] = ''

View File

@ -85,12 +85,16 @@ class SchemaDiffObjectCompare:
len(source) <= 0 and len(target) <= 0):
return None
return compare_dictionaries(self, source_params, target_params,
target_schema, source, target,
self.node_type,
gettext(self.blueprint.COLLECTION_LABEL),
ignore_whitespaces,
self.keys_to_ignore)
return compare_dictionaries(view_object=self,
source_params=source_params,
target_params=target_params,
target_schema=target_schema,
source_dict=source,
target_dict=target,
node=self.node_type,
node_label=self.blueprint.COLLECTION_LABEL,
ignore_whitespaces=ignore_whitespaces,
ignore_keys=self.keys_to_ignore)
def ddl_compare(self, **kwargs):
"""

View File

@ -19,25 +19,23 @@ list_keys_array = ['name', 'colname', 'argid', 'token', 'option', 'conname',
'member_name', 'label', 'attname']
def compare_dictionaries(view_object, source_params, target_params,
target_schema, source_dict, target_dict, node,
node_label, ignore_whitespaces,
ignore_keys=None):
def compare_dictionaries(**kwargs):
"""
This function will compare the two dictionaries.
:param view_object: View Object
:param source_params: Source Parameters
:param target_params: Target Parameters
:param target_schema: Target Schema Name
:param source_dict: First Dictionary
:param target_dict: Second Dictionary
:param node: node type
:param node_label: node label
:param ignore_whitespaces: If set the True then ignore whitespaces
:param ignore_keys: List of keys that will be ignored while comparing
:param kwargs:
:return:
"""
view_object = kwargs.get('view_object')
source_params = kwargs.get('source_params')
target_params = kwargs.get('target_params')
target_schema = kwargs.get('target_schema')
source_dict = kwargs.get('source_dict')
target_dict = kwargs.get('target_dict')
node = kwargs.get('node')
node_label = kwargs.get('node_label')
ignore_whitespaces = kwargs.get('ignore_whitespaces')
ignore_keys = kwargs.get('ignore_keys', None)
dict1 = copy.deepcopy(source_dict)
dict2 = copy.deepcopy(target_dict)
@ -179,8 +177,11 @@ def compare_dictionaries(view_object, source_params, target_params,
target_ddl = \
view_object.get_sql_from_table_diff(**temp_tgt_params)
diff_ddl = view_object.get_sql_from_submodule_diff(
temp_src_params, temp_tgt_params, target_schema,
dict1[key], dict2[key], diff_dict, ignore_whitespaces)
source_params=temp_src_params,
target_params=temp_tgt_params,
target_schema=target_schema,
source=dict1[key], target=dict2[key], diff_dict=diff_dict,
ignore_whitespaces=ignore_whitespaces)
else:
temp_src_params = copy.deepcopy(source_params)
temp_tgt_params = copy.deepcopy(target_params)