0

I'm using the unaccent extension for Postgres and followed all the docs to get it to work (installed the extension directly via CREATE EXTENSION and put django.contrib.postgres in INSTALLED_APPS in django settings).

In local environment it's working perfectly however after building and deploying the app to Heroku it looks like it isn't installing django.contrib.postgres. Therefore when i try to use the functionality of my app that queries using unaccent i get the "Unsupported lookup 'unaccent' for CharField" that happens when you don't have django.contrib.postgres in INSTALLED_APPS.

In python shell printing settings.INSTALLED_APPS on local environment shows that django.contrib.postgres is there, but running it on Heroku shows it's missing. Is it unsupported by the buildpack for heroku/python or something or am i missing some config?

I tried to pip install the django-contrib-postgres backport for earlier versions of Django (put it in requirements.txt) to no avail. Python version is 3.6.7 and Django is 2.1.2. Creating the extension using migrations with UnaccentExtension doesn't change anything either and i'm sure it's not Postgres problem because querying directly on the database using unaccent(columnname) works as expected.

Thanks in advance.

Edit: YAML definition for Azure DevOps Pipelines and requirements.txt

requirements.txt

Django==2.1.2
django-cors-middleware==1.3.1
django-heroku==0.3.1
django-oauth-toolkit==1.2.0
djangorestframework==3.9.0
djangorestframework-camel-case==0.2.0
django-contrib-postgres==0.0.1
facepy==1.0.9
factory_boy==2.11.1
flake8==3.5.0
gunicorn==19.8.1
psycopg2-binary==2.7.5
pylint==2.1.1
pytest==3.9.1
pytest-cov==2.6.0
pytest-django==3.4.3
python-dateutil==2.7.5
raven==6.9.0
freezegun==0.3.11
mailchimp3==3.0.4

Build

pool:

  name: Hosted VS2017

steps:

- task: UsePythonVersion@0

  displayName: 'Use Python 3.6'

  inputs:

    versionSpec: 3.6



- script: 'pip install -r requirements.txt'

  workingDirectory: 'back-end'

  displayName: 'Restore dependencies'



- script: 'python manage.py collectstatic'

  workingDirectory: 'back-end'

  displayName: 'Export static files'



- script: 'flake8 .'

  workingDirectory: 'back-end'

  displayName: 'Style analysis'



- script: 'pytest --junitxml=junit.xml --cov --cov-report=xml --cov-report=html'

  workingDirectory: 'back-end'

  displayName: 'Run tests'



- task: PublishTestResults@2

  displayName: 'Publish test results'

  inputs:

    testResultsFiles: 'back-end/junit.xml'



- task: PublishCodeCoverageResults@1

  displayName: 'Publish test coverage'

  inputs:

    codeCoverageTool: Coverage

    summaryFileLocation: '$(System.DefaultWorkingDirectory)/back-end/coverage.xml'

    reportDirectory: '$(System.DefaultWorkingDirectory)/back-end/htmlcov/'



- task: PublishBuildArtifacts@1

  displayName: 'publish artifact'

  inputs:

    PathtoPublish: 'back-end'

    ArtifactName: BackendArtifact




Release (key and names are hidden with *)

steps:

- task: boostingmy.vsts-heroku-tasks.pushu-to-heroku.PushToHeroku@1

  displayName: 'Publish on Heroku'

  inputs:

    ApiKey: '***'

    AppName: '***'

    PushRoot: '$(System.DefaultWorkingDirectory)/****-Back-end-CI/BackendArtifact'


RK Dev
  • 1
  • 3
  • "In python shell printing settings.INSTALLED_APPS on local environment shows that django.contrib.postgres is there, but running it on Heroku shows it's missing"—are you _entirely_ sure you've deployed the right version? You don't have local uncommitted changes, and your most recent local commit matches what you see in [`heroku releases`](https://devcenter.heroku.com/articles/releases#listing-release-history)? – ChrisGPT was on strike May 10 '19 at 05:23
  • Yes. In heroku releases i see a different hash on the last version deployed (couldn't find it in my local repository, dunno if its because we use Azure DevOps pipelines to build and release/push to Heroku) so i cloned the heroku master to check if the settings for production have the contrib.postgres entry and it is there. – RK Dev May 10 '19 at 12:26
  • "we use Azure DevOps pipelines"—oh. That's probably important information. What does your pipeline do? Can you share its definition with us? – ChrisGPT was on strike May 10 '19 at 12:47
  • Edited the question with YAML for Build and Release pipelines. Basically we get the sources from master, configure Python version, install pip requirements and run some tests and linting before publishing the artifact on Azure DevOps to be used later by the Release pipeline that push it to Heroku. – RK Dev May 10 '19 at 13:38
  • Thanks. I don't see anything there that would modify your `INSTALLED_APPS`. Is there any other way that you can verify that the source revision (not the deployed artifact) contains the correct `INSTALLED_APPS` value? – ChrisGPT was on strike May 10 '19 at 14:22
  • Besides doing a checkout in master and building/running locally i don't think so. Running locally it's working fine, this one is really a mistery. As a workaround i created another column in the database and saved the original string with accentuations there using unidecode from PyPI to remove it and pointed the query to use it. Thank you for your time @Chris , really appreciate it and i'll keep researching. Should i post an answer detailing the workaround? – RK Dev May 10 '19 at 15:40
  • My point is to make sure you're looking at the same _commit_. `master` is probably a branch, and it can point to any commit. Anyway, if you think you've found a solution feel free to post it. [Self-answering is encouraged here](https://stackoverflow.com/help/self-answer). – ChrisGPT was on strike May 10 '19 at 15:59
  • Thanks. Yes it's the same commit, i could tell just by the modifications that were done since we changed a lot of stuff in front-end and some minor changes were in the same commit of the configuration of installed_apps, and they were published. – RK Dev May 10 '19 at 16:21

0 Answers0