#28975 - Skip automatic creation of postgis extension if it already exists

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

#28975 - Skip automatic creation of postgis extension if it already exists

Niclas Kron
Hello,
I am writing to you to establish some sort of consensus on how to proceed with this bug/PR:


With regard to the problem - the current implementation is that a query is ran to determine
if the extension exists or not in the current database. That query unlike `CREATE EXTENSION ...`
does not require superuser status on the executing database user.

The pros and cons for this implementation:

### Pros
* Operates as normal with the only addition that if it already exists we dont
run the CREATE EXTENSION thus the application wont fail if the user is a non-superuser.

### Cons:
* Hard to test due to the fragility of the tests

By hard to test, I mean that I can't easily test it because current implementation leads some sort of race condition
and sometimes the tests fail. At least if you look at my current tests (yes I am a new to this).

I did talk about this on the irc channel #django and #django-dev to try to solve it - however
the recommendation was to write on the mailing list to try to establish a consensus on a proper
way to go forward. This especially since another create suggestion was put forward by Ramiro Morales

This simply suggests to remove the automatic creation all together and have the user do it explicitly
either via:

> Manually, externally -- For cases like the OP describes
> Via a migration -- For cases in which the user Django connects to Postgres as has DB superuser rights there as it's assumed

So my question is rather - which option does make most sense and also which one does not break any existing applications
that might rely on this - or is that not an issue? From my talks on irc it seems like this sort of change wont be backported to say 1.11.x.

PS. Maybe its better with a solution that fits the case for *ANY* extension since creation of any extension will either way
require superuser status.

Any guidance or help would be appreciated as I am very eager to make my first ever contribution :-)

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/deeaba31-8d7f-4763-a0b4-48d250944404%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: #28975 - Skip automatic creation of postgis extension if it already exists

Ramiro Morales-2


On Wed, Jan 10, 2018 at 3:12 AM, Niclas Kron <[hidden email]> wrote:
Hello,
I am writing to you to establish some sort of consensus on how to proceed with this bug/PR:


With regard to the problem - the current implementation is that a query is ran to determine
if the extension exists or not in the current database. That query unlike `CREATE EXTENSION ...`
does not require superuser status on the executing database user.

The pros and cons for this implementation:

### Pros
* Operates as normal with the only addition that if it already exists we dont
run the CREATE EXTENSION thus the application wont fail if the user is a non-superuser.

### Cons:
* Hard to test due to the fragility of the tests

By hard to test, I mean that I can't easily test it because current implementation leads some sort of race condition
and sometimes the tests fail. At least if you look at my current tests (yes I am a new to this).

I did talk about this on the irc channel #django and #django-dev to try to solve it - however
the recommendation was to write on the mailing list to try to establish a consensus on a proper
way to go forward. This especially since another create suggestion was put forward by Ramiro Morales

 
Please disregard that comment as I posted it before or in parallel with the discussion you and Tim were
having via the GitHub PR about a non-admin Postgres user being able to introspect at runtime if the
postgis extension is installed or not.

Had considered the idea myself bud assumed it woudn't be possible or that it would introuduce too
much complexityto the code. Was wrong on both counts.


Regards,

--
Ramiro Morales
@ramiromorales

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAO7PdF8PXETx%3D%2BP2DqgX0CetuzPDk5Gb2E5dF%3Dd7TL55nn8BxA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: #28975 - Skip automatic creation of postgis extension if it already exists

Shai Berger
As far as I know, Postgres is smart enough that the SQL statement

        CREATE EXTENSION IF NOT EXISTS postgis

actually fails on permissions, only if the extension doesn't exist (we
ran into a very similar issue with the 'hstore' extension just the
other day).

So long as that is true -- I don't really see a problem here. If the
extension is installed, there will be no error; if it isn't, and the
user doesn't have permissions to create it, I see little difference
between an error when setting up the database and an error encountered
in migrations.

Shai.

On Thu, 11 Jan 2018 07:59:05 -0300
Ramiro Morales <[hidden email]> wrote:

> On Wed, Jan 10, 2018 at 3:12 AM, Niclas Kron <[hidden email]>
> wrote:
>
> > Hello,
> > I am writing to you to establish some sort of consensus on how to
> > proceed with this bug/PR:
> >
> > * PR https://github.com/django/django/pull/9518
> > * BUG https://code.djangoproject.com/ticket/28975
> >
> > With regard to the problem - the current implementation is that a
> > query is ran to determine
> > if the extension exists or not in the current database. That query
> > unlike `CREATE EXTENSION ...`
> > does not require superuser status on the executing database user.
> >
> > The pros and cons for this implementation:
> >
> > ### Pros
> > * Operates as normal with the only addition that if it already
> > exists we dont
> > run the CREATE EXTENSION thus the application wont fail if the user
> > is a non-superuser.
> >
> > ### Cons:
> > * Hard to test due to the fragility of the tests
> >
> > By hard to test, I mean that I can't easily test it because current
> > implementation leads some sort of race condition
> > and sometimes the tests fail. At least if you look at my current
> > tests (yes I am a new to this).
> >
> > I did talk about this on the irc channel #django and #django-dev to
> > try to solve it - however
> > the recommendation was to write on the mailing list to try to
> > establish a consensus on a proper
> > way to go forward. This especially since another create suggestion
> > was put forward by Ramiro Morales
> > as per: https://code.djangoproject.com/ticket/28975#comment:5
> >
> >  
> Please disregard that comment as I posted it before or in parallel
> with the discussion you and Tim were
> having via the GitHub PR about a non-admin Postgres user being able to
> introspect at runtime if the
> postgis extension is installed or not.
>
> Had considered the idea myself bud assumed it woudn't be possible or
> that it would introuduce too
> much complexityto the code. Was wrong on both counts.
>
>
> Regards,
>

--
You received this message because you are subscribed to the Google Groups "Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/20180112191150.779cd7a1.shai%40platonix.com.
For more options, visit https://groups.google.com/d/optout.