Remove extra brackets from reverse engineering SQL of RLS Policy. Fixes #5621

This commit is contained in:
Akshay Joshi 2020-06-30 16:11:02 +05:30
parent 88db5ec4d5
commit 46d26cd029
5 changed files with 28 additions and 16 deletions

View File

@ -19,4 +19,5 @@ Bug fixes
*********
| `Issue #3851 <https://redmine.postgresql.org/issues/3851>`_ - Add proper indentation to the code while generating functions, procedures, and trigger functions.
| `Issue #5621 <https://redmine.postgresql.org/issues/5621>`_ - Remove extra brackets from reverse engineering SQL of RLS Policy.
| `Issue #5630 <https://redmine.postgresql.org/issues/5630>`_ - Fixed an issue where installation of pgadmin4 not working on 32-bit Windows.

View File

@ -186,6 +186,16 @@ def get_sql(conn, data, did, tid, idx, datlastsysoid,
raise ObjectGone(_('Could not find the index in the table.'))
old_data = dict(res['rows'][0])
# Remove opening and closing bracket as we already have in jinja
# template.
if 'using' in old_data and old_data['using'] is not None and \
old_data['using'].startswith('(') and \
old_data['using'].endswith(')'):
old_data['using'] = old_data['using'][1:-1]
if 'withcheck' in old_data and old_data['withcheck'] is not None and \
old_data['withcheck'].startswith('(') and \
old_data['withcheck'].endswith(')'):
old_data['withcheck'] = old_data['withcheck'][1:-1]
# If name is not present in data then
# we will fetch it from old data, we also need schema & table name

View File

@ -326,9 +326,17 @@ class RowSecurityView(PGChildNodeView):
data = dict(res['rows'][0])
res = data
# Remove opening and closing bracket as we already have in jinja
# template.
if 'using' in data and data['using'] is not None and \
data['using'].startswith('(') and data['using'].endswith(')'):
data['using'] = data['using'][1:-1]
if 'withcheck' in data and data['withcheck'] is not None and \
data['withcheck'].startswith('(') and \
data['withcheck'].endswith(')'):
data['withcheck'] = data['withcheck'][1:-1]
return True, res
return True, data
@check_precondition
def create(self, gid, sid, did, scid, tid):
@ -527,15 +535,10 @@ class RowSecurityView(PGChildNodeView):
"""
This function will generate sql to render into the sql panel
"""
sql = render_template("/".join(
[self.template_path, 'properties.sql']), plid=plid)
status, res = self.conn.execute_dict(sql)
status, res_data = self._fetch_properties(plid)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(gettext("""Could not find the policy in the table."""))
res = dict(res['rows'][0])
res_data = res
return res_data
res_data['schema'] = self.schema
res_data['table'] = self.table

View File

@ -70,16 +70,15 @@ def get_sql(conn, data, did, tid, plid, datlastsysoid, schema, table,
if plid is not None:
sql = render_template("/".join(
[template_path, 'properties.sql']), plid=plid)
status, res = conn.execute_dict(sql)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
raise ObjectGone(_('Could not find the index in the table.'))
res_data = dict(res['rows'][0])
res = res_data
old_data = res
old_data = dict(res['rows'][0])
old_data['schema'] = schema
old_data['table'] = table
sql = render_template(
@ -91,6 +90,7 @@ def get_sql(conn, data, did, tid, plid, datlastsysoid, schema, table,
data['table'] = table
sql = render_template("/".join(
[template_path, 'create.sql']), data=data)
return sql, data['name'] if 'name' in data else old_data['name']

View File

@ -15,5 +15,3 @@ WHERE
{% if tid %}
pl.polrelid = {{ tid }}
{% endif %};