AdrianFerJ / v2go-api

V2go web app's repo contains client and server apps (django and angular), and infastructure setup for both apps, postgres, redis, and nginx using docker
0 stars 0 forks source link

Unable to create user #3

Closed niroigen closed 5 years ago

niroigen commented 5 years ago

When attempting to create a new user using the api endpoint http://127.0.0.1:8000/api/sign_up/, it ends up creating the error that can be seen in below.

image image

Although when running tests for the application it does not return any failure.

AdrianFerJ commented 5 years ago

@niroigen , I have pushed some changes to the development branch (as I mentioned yesterday, it was ahead of origin by a few commits). Also, I am about to create a PR with fixes to old model references (before we stored the address in location, now it's called address and geo_location is the geoPoint). Now all tests are passing.

I have tried to reproduce your problem and I don't encounter any problems with sign_up or creating users. So, I think the bug you are experiencing has to do with an incomplete transition to postgres+ postGis. My bad, because I didn't hadn't pushed the last commits on dev branch. But it's now up to date.

Lastly, since the tests didn't fail when you had the problem, I think we should take advantage of the situation to improve the test cases. so, before rebasing your dev branch and approving the PR, could you create a test that fails in your current environment? Then, approve the PR, rebase your branch and if everything goes well, your test should pass.

niroigen commented 5 years ago

Understood, I will modify the test so it can display a failure. I approved the pull request, but like you said I will not rebase until I modify the changes and once the test actually works I will then rebase.

niroigen commented 5 years ago

@driankus Turns out that the reason as to why the tests was working was indeed because that the database was set to

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

So in the tests what I did now is that I would verify whether the default database is set to postgres, and it fails now saying it is set to sqlite3.

My issue now is setting up postgres. I have installed it on my system. Installed all the dependencies for GeoDjango, created a database called pg_gis_db and created a superuser for it
'USER': 'dev_user', 'PASSWORD': 'SirGeorgeWilliams1515',, I'm getting an issue where it is saying

Applying admin.0001_initial...Traceback (most recent call last):
  File "/Users/taranraina/.local/share/virtualenvs/django-server-4baaf__R/lib/python3.7/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: relation "volt_finder_user" does not exist

The above exception was the direct cause of the following exception:

Traceback

 (most recent call last):
 File "./manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/taranraina/.local/share/virtualenvs/django-server-4baaf__R/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/Users/taranraina/.local/share/virtualenvs/django-server-4baaf__R/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/taranraina/.local/share/virtualenvs/django-server-4baaf__R/lib/python3.7/site-packages/django/core/management/base.py", line 316, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/taranraina/.local/share/virtualenvs/django-server-4baaf__R/lib/python3.7/site-packages/django/core/management/base.py", line 353, in execute
    output = self.handle(*args, **options)
  File "/Users/taranraina/.local/share/virtualenvs/django-server-4baaf__R/lib/python3.7/site-packages/django/core/management/base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "/Users/taranraina/.local/share/virtualenvs/django-server-4baaf__R/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 203, in handle
    fake_initial=fake_initial,
  File "/Users/taranraina/.local/share/virtualenvs/django-server-4baaf__R/lib/python3.7/site-packages/django/db/migrations/executor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/Users/taranraina/.local/share/virtualenvs/django-server-4baaf__R/lib/python3.7/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/Users/taranraina/.local/share/virtualenvs/django-server-4baaf__R/lib/python3.7/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/Users/taranraina/.local/share/virtualenvs/django-server-4baaf__R/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 106, in __exit__
    self.execute(sql)
  File "/Users/taranraina/.local/share/virtualenvs/django-server-4baaf__R/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 133, in execute
    cursor.execute(sql, params)
  File "/Users/taranraina/.local/share/virtualenvs/django-server-4baaf__R/lib/python3.7/site-packages/django/db/backends/utils.py", line 100, in execute
    return super().execute(sql, params)
  File "/Users/taranraina/.local/share/virtualenvs/django-server-4baaf__R/lib/python3.7/site-packages/django/db/backends/utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/Users/taranraina/.local/share/virtualenvs/django-server-4baaf__R/lib/python3.7/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/Users/taranraina/.local/share/virtualenvs/django-server-4baaf__R/lib/python3.7/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "/Users/taranraina/.local/share/virtualenvs/django-server-4baaf__R/lib/python3.7/site-packages/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/Users/taranraina/.local/share/virtualenvs/django-server-4baaf__R/lib/python3.7/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "volt_finder_user" does not exist

when I try to do a ./manage.py migrate. Perhaps I am doing something wrong, let me know what you think.

AdrianFerJ commented 5 years ago

hey @niroigen. I'm not sure but my guess is that it has to be one of 3 options: db configuration in settings.py (less likely, after what you described), incorrect import in models.py (you should be importing models from django.contrib.gis.db and AbstractUser from django.contrib.auth.models), or perhaps is due to an inconsistencies in one of your migrations (try wiping all migrations and making migrations from scratch)

But, before you troubleshoot, make sure you check/test the changes on fix_postGres. Since you already created a test that fails if postgres+postgis is not working, you could test fix_postGres and approve the PR. Then rebase your branch (with the new tests) with the updated development branch, and run your tests. If they pass, you can go ahead and make a PR. https://github.com/driankus/v2go-web-app/tree/fix_postGres

AdrianFerJ commented 5 years ago

Issue fixed