public inbox for [email protected]  
help / color / mirror / Atom feed
From: Murtuza Zabuawala <[email protected]>
To: Dave Page <[email protected]>
Cc: pgadmin-hackers <[email protected]>
Subject: Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4)
Date: Wed, 27 Jul 2016 18:07:41 +0530
Message-ID: <CAKKotZQmyVg8eJD8+Ha+fNg=MUX_i6YcUJCkJwzp_sWf3mC=uA@mail.gmail.com> (raw)
In-Reply-To: <CA+OCxoxf9shrYLa_WyZL5V2FKxV+Mu2UfjCBJCFNv50qyCrJwQ@mail.gmail.com>
References: <CAKKotZR5b=JjkC5cS2x=TzVY2MfEhc+eHpcbMm41eW5jv4uYBA@mail.gmail.com>
	<CA+OCxow2ZO0RRELTnQo45o+mqX6GJpEEHzuZYGg0g6D6msb_9w@mail.gmail.com>
	<CAKKotZQNGSBSa=XjhKfDgBgMpAXEQUaMrBnNkW_F58q2CkdvLQ@mail.gmail.com>
	<CA+OCxoxcKKbHqmhaaOZKQLk1tqTkpereYzN5vCz3zS3oZbUM7A@mail.gmail.com>
	<CAKKotZRH-go6m2uhpVOs9-ps4SiLFvfbjeV5mf9NK+=GztToXw@mail.gmail.com>
	<CA+OCxozYsK_aV5Gwh95-dm4m3HoeS8VS4KwX4Ds7PUXcvmH6eg@mail.gmail.com>
	<CA+OCxowMFzdQm1fQPPAPF3je_-x6oh95XPYX3rW27R0DkYsVFQ@mail.gmail.com>
	<CAKKotZT2YcvNF-cr3XV_EGiWhc-mPvGZCe5r62YFYbx6Zxvhyw@mail.gmail.com>
	<CA+OCxoxf9shrYLa_WyZL5V2FKxV+Mu2UfjCBJCFNv50qyCrJwQ@mail.gmail.com>
List-Unsubscribe:  <mailto:[email protected]?body=unsub%20pgadmin-hackers>

Okay, Let me check on that.

Meanwhile I'm attaching patch for making Provider optional in security
labels control.

Regards,
Murtuza

--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

On Wed, Jul 27, 2016 at 5:04 PM, Dave Page <[email protected]> wrote:

> Hi
>
> On Wed, Jul 27, 2016 at 12:18 PM, Murtuza Zabuawala
> <[email protected]> wrote:
> > Hi Dave,
> >
> > 1) Unicode conversion was working properly for function node, It was
> failing
> > due to wrong sql templates.
> > - I've fixed them.
>
> I just did a test, and it's still failing - see the attached
> screenshot. Aside from the encoding issue, it looks like it's adding
> extra quotes around the parameter data type - double-double quoting
> the schema and type, and then quoting the whole lot again in the
> CREATE part. The ALTER part looks fine.
>
> > 2) Type is also working fine with encoding for me(PFA screenshots), Can
> you
> > please provide error you got?
>
> Hmm, I can't reproduce that now. Weird.
>
> > This patch also makes Provider optional in security label control &
> > templates.
> >
> > -------
> > Regarding enforcing to utf-8, In my opinion we can enforce everything to
> > utf-8 if we use any of one python version but to make it compatible with
> > both python2 and python3 version by forcing utf-8 encoding it will be
> > difficult to handle its side effects.
>
> Urgh. Ok, thanks.
>
> > Python2,
> >
> >>>> txt_sample = 'Hello'
> >>>> isinstance(txt_sample, str)
> > True
> >>>> isinstance(txt_sample, bytes)
> > True
> >>>> isinstance(txt_sample, unicode)
> > False
> >>>> txt_sample.encode('utf-8')
> > 'Hello'
> >>>> txt_sample.decode('utf-8')
> > u'Hello'
> >
> > Forcing to unicode in Python2,
> >
> >>>> txt_sample = u'Hello'
> >>>> isinstance(txt_sample, str)
> > False
> >>>> isinstance(txt_sample, bytes)
> > False
> >>>> isinstance(txt_sample, unicode)
> > True
> >
> > Python3,
> >
> >>>> txt_sample = 'Hello'
> >>>> isinstance(txt_sample, str)
> > True
> >>>> isinstance(txt_sample, bytes)
> > False
> >>>> txt_sample.encode('utf-8')
> > b'Hello'
> >>>> txt_sample.decode('utf-8')
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in <module>
> > AttributeError: 'str' object has no attribute 'decode'
> >
> >
> > And also psycopg2 driver returns text as string in Python2 even if that
> text
> > contains unicode characters, In python3 that just works fine because
> string
> > is Unicode by default.
> >
> >
> > Regards,
> > Murtuza
> >
> > --
> > Regards,
> > Murtuza Zabuawala
> > EnterpriseDB: http://www.enterprisedb.com
> > The Enterprise PostgreSQL Company
>
>
>
> --
> Dave Page
> Blog: http://pgsnake.blogspot.com
> Twitter: @pgsnake
>
> EnterpriseDB UK: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>


-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers


Attachments:

  [application/octet-stream] Fix_SecLabls.patch (5.3K, 3-Fix_SecLabls.patch)
  download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/macros/security.macros b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/macros/security.macros
index 39587c3..1beb259 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/macros/security.macros
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/macros/security.macros
@@ -1,6 +1,6 @@
 {% macro APPLY(conn, type, schema_name, parent_object, child_object, provider, label) -%}
-SECURITY LABEL FOR {{ conn|qtIdent(provider) }} ON {{ type }} {{ conn|qtIdent(schema_name, parent_object, child_object) }} IS {{ label|qtLiteral }};
+SECURITY LABEL{% if provider and provider != '' %} FOR {{ conn|qtIdent(provider) }}{% endif %} ON {{ type }} {{ conn|qtIdent(schema_name, parent_object, child_object) }} IS {{ label|qtLiteral }};
 {%- endmacro %}
 {% macro DROP(conn, type, schema_name, parent_object, child_object, provider) -%}
-SECURITY LABEL FOR {{ conn|qtIdent(provider) }} ON {{ type }} {{ conn|qtIdent(schema_name, parent_object, child_object) }} IS NULL;
+SECURITY LABEL{% if provider and provider != '' %} FOR {{ conn|qtIdent(provider) }}{% endif %} ON {{ type }} {{ conn|qtIdent(schema_name, parent_object, child_object) }} IS NULL;
 {%- endmacro %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/macros/functions/security.macros b/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/macros/functions/security.macros
index dd2a086..5d9e2a6 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/macros/functions/security.macros
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/macros/functions/security.macros
@@ -2,7 +2,7 @@
 {# Macros for Security Labels (functions module) #}
 {#################################################}
 {% macro SET(conn, type, name, provider, label, schema, func_args) -%}
-SECURITY LABEL FOR {{ provider }} ON {{ type }} {{ conn|qtIdent(schema, name) }}({{func_args}}) IS {{ label|qtLiteral }};
+SECURITY LABEL{% if provider and provider != '' %} FOR {{ conn|qtIdent(provider) }}{% endif %} ON {{ type }} {{ conn|qtIdent(schema, name) }}({{func_args}}) IS {{ label|qtLiteral }};
 {%- endmacro %}
 {% macro UNSET(conn, type, name, provider, schema, func_args) -%}
 SECURITY LABEL FOR {{ provider }} ON {{ type }} {{ conn|qtIdent(schema, name) }}({{func_args}}) IS NULL;
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/macros/schemas/security.macros b/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/macros/schemas/security.macros
index e1126b1..7d764c5 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/macros/schemas/security.macros
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/macros/schemas/security.macros
@@ -2,7 +2,7 @@
 {# Macros for schema and its child nodes  #}
 {##########################################}
 {% macro SET(conn, type, name, provider, label, schema) -%}
-SECURITY LABEL FOR {{ provider }} ON {{ type }} {{ conn|qtIdent(schema, name) }} IS {{ label|qtLiteral }};
+SECURITY LABEL FOR{% if provider and provider != '' %} FOR {{ conn|qtIdent(provider) }}{% endif %} ON {{ type }} {{ conn|qtIdent(schema, name) }} IS {{ label|qtLiteral }};
 {%- endmacro %}
 {% macro UNSET(conn, type, name, provider, schema) -%}
 SECURITY LABEL FOR {{ provider }} ON {{ type }} {{ conn|qtIdent(schema, name) }} IS NULL;
diff --git a/web/pgadmin/browser/server_groups/servers/templates/macros/security.macros b/web/pgadmin/browser/server_groups/servers/templates/macros/security.macros
index 83fb9d2..4350f9a 100644
--- a/web/pgadmin/browser/server_groups/servers/templates/macros/security.macros
+++ b/web/pgadmin/browser/server_groups/servers/templates/macros/security.macros
@@ -1,5 +1,5 @@
 {% macro APPLY(conn, type, name, provider, label) -%}
-SECURITY LABEL FOR {{ conn|qtIdent(provider) }} ON {{ type }} {{ conn|qtIdent(name) }} IS {{ label|qtLiteral }};
+SECURITY LABEL{% if provider and provider != '' %} FOR {{ conn|qtIdent(provider) }}{% endif %} ON {{ type }} {{ conn|qtIdent(name) }} IS {{ label|qtLiteral }};
 {%- endmacro %}
 {% macro DROP(conn, type, name, provider) -%}
 SECURITY LABEL FOR {{ conn|qtIdent(provider) }} ON {{ type }} {{ conn|qtIdent(name) }} IS NULL;
diff --git a/web/pgadmin/browser/server_groups/servers/templates/servers/servers.js b/web/pgadmin/browser/server_groups/servers/templates/servers/servers.js
index 1c8bff8..0a64143 100644
--- a/web/pgadmin/browser/server_groups/servers/templates/servers/servers.js
+++ b/web/pgadmin/browser/server_groups/servers/templates/servers/servers.js
@@ -23,14 +23,6 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
           errmsg = null;
         this.errorModel.clear();
 
-        if (_.isUndefined(this.get('provider')) ||
-          _.isNull(this.get('provider')) ||
-          String(this.get('provider')).replace(/^\s+|\s+$/g, '') == '') {
-            errmsg = '{{ _('Provider must be specified.') }}';
-            this.errorModel.set('provider', errmsg);
-            return errmsg;
-        }
-
         if (_.isUndefined(this.get('label')) ||
           _.isNull(this.get('label')) ||
           String(this.get('label')).replace(/^\s+|\s+$/g, '') == '') {


view thread (16+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4)
  In-Reply-To: <CAKKotZQmyVg8eJD8+Ha+fNg=MUX_i6YcUJCkJwzp_sWf3mC=uA@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox