Skip to content
This repository has been archived by the owner on Apr 12, 2021. It is now read-only.

Enabling social-auth breaks manage.py prep #106

Open
telenieko opened this issue Feb 28, 2019 · 8 comments
Open

Enabling social-auth breaks manage.py prep #106

telenieko opened this issue Feb 28, 2019 · 8 comments

Comments

@telenieko
Copy link

Hi there,
I'm on python 3.6.8, lino==19.2.2, lino-xl==19.2.0;

When I follow the social authentication page on the book mange.py prep won't work anymore.

In my Site class I do: social_auth_backends = [ 'social_core.backends.google.GoogleOAuth2', ], and then set the appropiate settings for the backend and when running prep this comes:

`initdb demo_users` started on database test.
Operations to perform:
  Apply all migrations: contenttypes, sessions, social_django
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying sessions.0001_initial... OK
  Applying social_django.0001_initial...

Traceback (most recent call last):
  File "lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: relation "users_user" does not exist

The furthest I came is that initdb does first the migrations and after migrations it does the non-migration capable applications. What happens (I think) is that modlib.users is not migration capable while social_django is.

So tables for social_django are created before modlib.users tables even exist, hence the exception.

@lsaffre
Copy link
Member

lsaffre commented Mar 1, 2019

Oh, I see psycopg2. And does it work with the default DATABASES settings (which use sqlite)?

@telenieko
Copy link
Author

telenieko commented Mar 1, 2019

Yes, sqlite works.
Note that to setup DATABASES what I'm doing is that I override Site.get_database_settings() to make it return None. Looking at the code it seemed like the cleanest way to have DATABASES untouched.

And I do not think that caused any bad side effects, but probably I'm wrong.

I'm doing so because I use django-environ to configure my settings (I plan to use Heroku and/or Docker to deploy).

@khchine5
Copy link
Member

khchine5 commented Mar 1, 2019

Hi @telenieko ,
Take a look at this demo project, it uses social_django.
https://github.com/lino-framework/book/blob/master/lino_book/projects/team/settings/demo.py
And In the case you want to use postgresql instead of mysql or sqlite ,try just to edit demo.py and add missing DATABASES settings as required by setting.py in any regular Django project.

@lsaffre
Copy link
Member

lsaffre commented Mar 2, 2019

Also if you want to have DATABASES untouched, just define it after the line SITE = Site(...) in your settings.py file.

@lsaffre
Copy link
Member

lsaffre commented Mar 2, 2019

We didn't yet use neither django-environ nor Heroku nor Docker so far. And I guess that we should do so. It's just a lack of time. Maybe one day you should give us some lessons...

@telenieko
Copy link
Author

Up to now what I've found is that SQLite works but psycopg2 does not.
python manage.py prep produces different results on each database, which might be a good clue:

On SQLite:

Operations to perform:
  Synchronize unmigrated apps: about, accounts, auth, bootstrap3, clients, contacts, countries, extjs, jinja, lino, office, printing, staticfiles, system, users, xl
  Apply all migrations: contenttypes, sessions, social_django
Synchronizing apps without migrations:

On PostgreSQL:

Operations to perform:
  Apply all migrations: contenttypes, sessions, social_django
Running migrations:

Crearly something's off there. Will keep investigatin.

@lsaffre
Copy link
Member

lsaffre commented Mar 5, 2019

Indeed, Lino's initdb command is not tested with PostgreSQL:
https://github.com/lino-framework/lino/blob/master/lino/management/commands/initdb.py
You probably need to change something in that code. But take care to change it only for postgresql.

@telenieko
Copy link
Author

From a quick glance to that file:

if engine == 'django.db.backends.postgresql':
            # a first time to create tables of contenttypes. At
            # least on PostgreSQL this is required because for
            # some reason the syncdb fails when contenttypes is
            # not initialized.
            call_command('migrate', **options)
call_command('migrate', '--run-syncdb', **options)

I'm willing to bet the problem is there. That running migrate first prevents the "--run-syncdb" to have any effect later. Will do some testing later

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants