Skip to content

Commit

Permalink
Prevent incorrect transaction abort
Browse files Browse the repository at this point in the history
  • Loading branch information
kostko committed Jun 29, 2017
1 parent 88a2ace commit 27d784f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions datastream/backends/influxdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,11 +722,14 @@ def _create_schema(self):
with self._metadata:
with self._metadata.cursor() as cursor:
try:
cursor.execute('SAVEPOINT create_schema')
cursor.execute('CREATE SCHEMA IF NOT EXISTS datastream')
except psycopg2.IntegrityError:
# Ignore an integrity error while creating the datastream schema. This may
# happen when the schema is created concurrently.
pass
# happen when the schema is created concurrently. We need to perform a rollback
# as otherwise the transaction will be aborted and all further commands will
# fail.
cursor.execute('ROLLBACK TO SAVEPOINT create_schema')

# Streams table.
cursor.execute('''CREATE TABLE IF NOT EXISTS datastream.streams (
Expand Down

0 comments on commit 27d784f

Please sign in to comment.