Django, PostgreSQL and CircleCI

postgresql
python
cci-20

#1

Since the release of CircleCI 2.0 I’m having hard time to make it works. I’ve big issue with PostgreSQL support. And it’s starting to drive me crazy. I’ve set up the postgresql db with :

    docker:
  - image: circleci/python:3.6.1
  - image: circleci/postgres:9.6.2
    environment:
      POSTGRES_USER: root
      POSTGRES_DB: circle_test 

And updated the settings for Django:

DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': 'circle_test',
        'HOST': '127.0.0.1',
        'PORT': '5432',
        'USERNAME': 'root',
        'PASSWORD': ''
    }
}

But I get the following error :

psycopg2.OperationalError: FATAL:  role "circleci" does not exist

Any idea how to solve this ?


#2

I’m not sure how to fix this immediately, but I can help you diagnose what is going on:

In the python image, the operating system user is set to circleci, which is a non-root for running tests. What seems to be happening is that Python’s Postgres driver is not honoring your configuration. Instead, it is using the Postgres default behavior where it attempts to connect to the localhost using the current username (e.g., if I run psql on my laptop, it will try to connect to the database david with the username david on localhost).

So the problem seems to be with how you are setting up the test environment configuration for Python/Django.


#3

Thanks, I’ve switched to this in my .circleci/config.yml :

docker:
  - image: circleci/python:3.6.1
  - image: mdillon/postgis:9.6
    environment:
      POSTGRES_USER: circleci
      POSTGRES_DB: circle_test 

And this django DATABASES config :

'default': {
    'ENGINE': 'django.contrib.gis.db.backends.postgis',
    'NAME': 'circle_test',
    'HOST': '127.0.0.1',
    'PORT': '5432',
    'USERNAME': 'circleci',
    'PASSWORD': ''
}

And it works (I’ve also switched to use a Postgis enabled PosgreSQL docker instance since I needed it)


How to execute psql command in postgres docker build
#4

Hey any thoughts on this post


#5

I’m hitting a similar problem. With the config below, I’ve not been able to find a postgres connection URL yet that will allow me to connect to the DB using node/pg-promise. Also getting Unhandled rejection error: role “circleci” does not exist


version: 2
jobs:
build:
docker:
- image: circleci/ruby:2.4.1-node-browsers
- image: circleci/postgres:9.6
POSTGRES_USER: circleci
POSTGRES_DB: cvrm
working_directory: "~/repo"
steps:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum “Gemfile.lock” }}-{{ checksum “package.json” }}
- v1-dependencies-
- run:
name: install dependencies
command: |
bundle install --jobs=4 --retry=3 --path vendor/bundle
npm install
- save_cache:
paths:
- “./vendor/bundle”
- “./node_modules"
key: v1-dependencies-{{ checksum “Gemfile.lock” }}-{{ checksum “package.json” }}
- run:
name: run tests
command: |
mkdir /tmp/test-results
# TEST_FILES=”(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)" # bundle exec rspec --format progress --format RspecJunitFormatter --out /tmp/test-results/rspec.xml --format progress "{TEST_FILES}"
pwd
bundle exec cucumber
- store_test_results:
path: “/tmp/test-results”
- store_artifacts:
path: "/tmp/test-results"
destination: test-results


#6

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.