opened
nataly-obr
username_0
**Description**
session.commit() method produces IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint.

**To Reproduce**
``` python
class Currency(Base):
    __tablename__ = 'currency'

    currency_code = db.Column('currency_code', db.String(3), primary_key=True)
    currency_name = db.Column('currency_name', db.String(140))

Session = sessionmaker(bind=self.engine)
session = Session()
currency_list = [Currency(currency_code = 'USD'), Currency(currency_code = 'EUR')]
currency_list = list(map(lambda x: session.merge(x), currency_list))
session.bulk_save_objects(currency_list, update_changed_only=False)
session.commit() 
```
**Additional information**

1. If I modify this code by adding session.commit() after session.merge(), everything works fine:
``` python
...
currency_list = list(map(lambda x: session.merge(x), currency_list))
session.commit() 
session.bulk_save_objects(currency_list, update_changed_only=False)
session.commit() 
```
2. The table 'currency' is empty, so the currency_code that I'm trying to add doesn't exist in the database.
3. Also no problem with adding this currency_code via 
``` python
connection = psycopg2.connect(...) 
... 
statement = "INSERT INTO {0} ({1}) VALUES ({2}); ".format(table, columns, values) 
crsr.execute(statement)  
connection.commit()
```
**Error**
``` python
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "currency_pkey"
DETAIL:  Key (currency_code)=(EUR) already exists.
```
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint
issue
closed
nataly-obr
username_0
issue
reopened
nataly-obr
username_0
**Description**
session.commit() method produces IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint.

**To Reproduce**
``` python
class Currency(Base):
    __tablename__ = 'currency'

    currency_code = db.Column('currency_code', db.String(3), primary_key=True)
    currency_name = db.Column('currency_name', db.String(140))

Session = sessionmaker(bind=self.engine)
session = Session()
currency_list = [Currency(currency_code = 'USD'), Currency(currency_code = 'EUR')]
currency_list = list(map(lambda x: session.merge(x), currency_list))
session.bulk_save_objects(currency_list, update_changed_only=False)
session.commit() 
```
**Additional information**

1. If I modify this code by adding session.commit() after session.merge(), everything works fine:
``` python
...
currency_list = list(map(lambda x: session.merge(x), currency_list))
session.commit() 
session.bulk_save_objects(currency_list, update_changed_only=False)
session.commit() 
```
2. The table 'currency' is empty, so the currency_code that I'm trying to add doesn't exist in the database.
3. Also no problem with adding this currency_code via 
``` python
connection = psycopg2.connect(...) 
... 
statement = "INSERT INTO {0} ({1}) VALUES ({2}); ".format(table, columns, values) 
crsr.execute(statement)  
connection.commit()
```
**Error**
``` python
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "currency_pkey"
DETAIL:  Key (currency_code)=(EUR) already exists.
```
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint
issue
closed
nataly-obr
username_0
issue