Parse-server: Postgres PostgresDuplicateRelationError

Created on 28 Aug 2017  Â·  7Comments  Â·  Source: parse-community/parse-server

We use GitHub Issues for bugs.

Issue Description

When I POST | /users, I get the error message show below.

Parse Server Log

Error: relation "unique_username" already exists
code:"42P07"
column:undefined
constraint:undefined
dataType:undefined
detail:undefined
file:"index.c"
hint:undefined
internalPosition:undefined
internalQuery:undefined
length:97
line:"793"
message:"relation "unique_username" already exists"
name:"error"
position:undefined
routine:"index_create"
schema:undefined
severity:"ERROR"
...

PostgresDuplicateRelationError
error.code === PostgresDuplicateRelationError
if (error.code === PostgresDuplicateRelationError && error.message.includes(constraintName)) {
  // Index already exists. Ignore error.
}

Postgres Log

ERROR:  relation "unique_username" already exists
STATEMENT:  ALTER TABLE "_User" ADD CONSTRAINT "unique_username" UNIQUE ("username")
ERROR:  relation "unique_name" already exists
STATEMENT:  ALTER TABLE "_Role" ADD CONSTRAINT "unique_name" UNIQUE ("name")
ERROR:  relation "unique_email" already exists
STATEMENT:  ALTER TABLE "_User" ADD CONSTRAINT "unique_email" UNIQUE ("email")
asdfasdfasdf
ERROR:  relation "unique_username" already exists
STATEMENT:  ALTER TABLE "_User" ADD CONSTRAINT "unique_username" UNIQUE ("username")
ERROR:  relation "unique_name" already exists
STATEMENT:  ALTER TABLE "_Role" ADD CONSTRAINT "unique_name" UNIQUE ("name")
ERROR:  relation "unique_email" already exists
STATEMENT:  ALTER TABLE "_User" ADD CONSTRAINT "unique_email" UNIQUE ("email")

I think that make signup endpoint slow. I have test my all endpoint.

test speed report

        ## User Collection [/users]
          ### Signing Up [POST]
            ✓ + userponse 201 (application/json) (120ms)
          ### Logging In [GET /login]
            ✓ + Response 200 (application/json) (86ms)
          ### Logging Out [POST /logout]
            ✓ + Response 200
          ### Retrieving User [GET /users/{objectId}]
            ✓ + Response 200 (application/json) (34ms)
          ### Retrieving Current User / Validationg Session Token [GET /me]
            ✓ + Response 200 (application/json) (44ms)
          ### Updating Users [PUT /users/{objectId}]
            ✓ + Response 200 (application/json) (33ms)
          ### Querying Users [GET]
            ✓ + Response 200 (application/json) (48ms)
          ### Deleting Users [DELETE]
            ✓ + Response 200 (application/json) (21ms)

Environment Setup

  • Server

    • parse-server version (Be specific! Don't say 'latest'.): 2.5.2
    • Operating System: macOS Sierra 10.12.6
    • Hardware: MacBook Pro (Retina, 13-inch, Early 2015)
    • Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): Localhost
  • Database

    • MongoDB version: None
    • Storage engine: Postgres
    • Hardware: MacBook Pro (Retina, 13-inch, Early 2015)
    • Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): Localhost

All 7 comments

@dplewis any idea?

@flovilmart I can try to look into it sometime this week.

Thanks man! Appreciated! :+1:

@trylovetom I've seen this error before but ignored it. I can't seem to reproduce it now. Can you write a test case or provide code to replicate the issue?

@dplewis I knew you ignored it,
@dplewis
Here are my test case

+process.env.NODE_ENV = 'test'
 +
 +const before = require('mocha').before
 +const it = require('mocha').it
 +const after = require('mocha').after
 +const chai = require('chai')
 +const chaiHttp = require('chai-http')
 +const server = require('index')
 +const config = require('config')
 +
 +chai.use(chaiHttp)
 +chai.should()
 +
 +module.exports = () => {
 +  let user
 +
 +  before('Create User', async () => {
 +    try {
 +      const res = await chai.request(server)
 +        .post(`${config.parse.mountPath}/users`)
 +        .send(require('./signingUp.request'))
 +        .set('X-Parse-Application-Id', config.parse.appId)
 +
 +      user = res.body
 +    } catch (err) {
 +      throw err
 +    }
 +  })
 +
 +  it('+ Response 200 (application/json)', async () => {
 +    try {
 +      const username = require('./signingUp.request').username
 +      const password = require('./signingUp.request').password
 +      const res = await chai.request(server)
 +        .get(`${config.parse.mountPath}/login`)
 +        .query({
 +          username: encodeURIComponent(username).replace(/%20/g, '+'), password: encodeURIComponent(password).replace(/%20/g, '+')
 +        })
 +        .set('X-Parse-Application-Id', config.parse.appId)
 +
 +      res.should.have.status(200)
 +
 +      user = res.body
 +      user.should.have.property('createdAt').with.be.a('string')
 +      user.should.have.property('updatedAt').with.be.a('string')
 +      user.should.have.property('objectId').with.be.a('string')
 +      user.should.have.property('sessionToken').with.be.a('string')
 +    } catch (err) {
 +      throw err
 +    }
 +  })
 +
 +  after('Delete User', async () => {
 +    try {
 +      await chai.request(server)
 +        .delete(`${config.parse.mountPath}/users/${user.objectId}`)
 +        .set('X-Parse-Application-Id', config.parse.appId)
 +        .set('X-Parse-Session-Token', user.sessionToken)
 +    } catch (err) {
 +      throw err
 +    }
 +  })
 +}

signingUp.request.json

+{
 +  "username": "LukeSkywalker",
 +  "password": "IHateMyFather",
 +  "phone": "415-392-0202",
 +  "email": "[email protected]"
 +} 

@trylovetom Do you get this error when you restart your localhost or when you run POST | users?

If you received this error when your localhost restarts this is the proper behavior. The error is ignored because the index exist when you restart. Since this check only happens once, the speed of your queries shouldn't be affected.

Yes, I create the new user before the test code of mocha.
Thanks for the update on the issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mohmagdy picture mohmagdy  Â·  3Comments

ugo-geronimo picture ugo-geronimo  Â·  3Comments

dpaid picture dpaid  Â·  3Comments

carjo422 picture carjo422  Â·  3Comments

pulse1989 picture pulse1989  Â·  3Comments