Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Containerize application, remove unused edit_data and make_races management commands #175

Merged
merged 7 commits into from
Nov 7, 2023

Conversation

hancush
Copy link
Member

@hancush hancush commented Nov 6, 2023

Description

This PR containerizes the application, to aid local development and in anticipation of migrating to Heroku from AWS.

Testing instructions

  • Pull down this branch, then follow the instructions in the updated README to run the application.
  • Navigate to http://localhost:8000 and confirm you see the homepage with data, etc. Click around and confirm nothing breaks.

@hancush hancush changed the title Containerize application Containerize application, remove unused edit_data and make_races management commands Nov 7, 2023
Copy link
Member

@derekeder derekeder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool - steps work as expected (with a few minor changes)

clicking around, most pages look good but these both give a DoesNotExist error:

http://localhost:8000/candidates/hector-balderas-3046/
http://localhost:8000/candidates/michelle-lujan-grisham-2243/

Here's the stack trace:

Environment:


Request Method: GET
Request URL: http://localhost:8000/candidates/michelle-lujan-grisham-2243/

Django Version: 1.11.29
Python Version: 3.6.15
Installed Applications:
['django_pdb',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.humanize',
 'bootstrap_pagination',
 'rest_framework',
 'camp_fin.apps.CampFinConfig',
 'pages.apps.PagesConfig',
 'ckeditor',
 'raven.contrib.django.raven_compat']
Installed Middleware:
['raven.contrib.django.middleware.DjangoRestFrameworkCompatMiddleware',
 'raven.contrib.django.middleware.SentryMiddleware',
 'django.middleware.cache.UpdateCacheMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.cache.FetchFromCacheMiddleware']



Traceback:

File "/usr/local/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py" in __get__
  178.             rel_obj = getattr(instance, self.cache_name)

During handling of the above exception ('Office' object has no attribute '_office_type_cache'), another exception occurred:

File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  41.             response = get_response(request)

File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py" in view
  68.             return self.dispatch(request, *args, **kwargs)

File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py" in dispatch
  88.         return handler(request, *args, **kwargs)

File "/usr/local/lib/python3.6/site-packages/django/views/generic/detail.py" in get
  116.         context = self.get_context_data(object=self.object)

File "/app/camp_fin/views.py" in get_context_data
  1191.                                         ot=latest_campaign.office.office_type.id,

File "/usr/local/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py" in __get__
  184.                 rel_obj = self.get_object(instance)

File "/usr/local/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py" in get_object
  159.         return qs.get(self.field.get_reverse_related_filter(instance))

File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py" in get
  380.                 self.model._meta.object_name

Exception Type: DoesNotExist at /candidates/michelle-lujan-grisham-2243/
Exception Value: OfficeType matching query does not exist.

README.md Outdated
To import the New Mexico campaign finance data into your database, run the `import_data` command:

```
```bash
python manage.py import_data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
python manage.py import_data
docker-compose run --rm app python manage.py import_data

README.md Outdated
python manage.py import_data
python manage.py make_search_index
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
python manage.py make_search_index
docker-compose run --rm app python manage.py make_search_index

@hancush
Copy link
Member Author

hancush commented Nov 7, 2023

Thanks, @derekeder. Fixed! To re-run the import, remove your generated data files, flush the data, then re-import:

rm data/*.csv data/*.xlsx
git checkout HEAD data
docker-compose run --rm app python manage.py flush_camp_fin
docker-compose run --rm app python manage.py import_data

Then check the pages that were erroring previously and confirm they work.

Comment on lines +633 to +636
# We've already popped the header row off the first sheet, above.
# Skip header row for subsequent sheets.
if idx > 0:
next(rows)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix.

Copy link
Member

@derekeder derekeder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix worked! looks good

@hancush hancush merged commit e966e99 into master Nov 7, 2023
1 check passed
@hancush hancush deleted the hcg/docker branch September 19, 2024 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants