Skip to content

Commit

Permalink
Ensure Import and Export task uses correct auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Davis Muro committed Dec 20, 2022
1 parent a4ec3f9 commit 37107aa
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion kpi/models/import_export_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import constance
import requests
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.postgres.fields import JSONField as JSONBField
from django.core.files.base import ContentFile
from django.db import models, transaction
Expand Down Expand Up @@ -203,7 +204,9 @@ def _run_task(self, messages):
# TODO: merge with `url` handling above; currently kept separate
# because `_load_assets_from_url()` uses complex logic to deal with
# multiple XLS files in a directory structure within a ZIP archive
headers = {"Authorization": f"Token {self.user.auth_token.key}"}
username = self.user.username
token = User.objects.using("kobocat").select_related("auth_token").get(username=username).auth_token.key
headers = {"Authorization": f"Token {token}"}
response = requests.get(
self.data['single_xls_url'], headers=headers)
response.raise_for_status()
Expand Down

0 comments on commit 37107aa

Please sign in to comment.