Skip to content

Commit

Permalink
Merge pull request #305 from hipster-philology/debug-postgres-conflit
Browse files Browse the repository at this point in the history
Debug postgres conflit
  • Loading branch information
Juliettejns authored Mar 6, 2024
2 parents 79f2577 + 3c5a4a2 commit 54c5999
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
13 changes: 13 additions & 0 deletions tests/db_fixtures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def add_control_lists(
cl = copy.deepcopy(DB_CORPORA[corpus]["control_list"])
db.session.add(cl)
db.session.commit()
# lorsque l'on force un exemple avec id l'autoincrémentation des id dans postgresql ne fonctionne pas par la suite.
if db.engine.dialect.name == "postgresql":
db.session.execute(
text("""SELECT setval(
Expand Down Expand Up @@ -136,6 +137,16 @@ def add_corpus(

db.session.add(corpus_object)
db.session.flush()
# lorsque l'on force un exemple avec id l'autoincrémentation des id dans postgresql ne fonctionne pas par la suite.
if db.engine.dialect.name == "postgresql":
db.session.execute(
text("""SELECT setval(
pg_get_serial_sequence('corpus', 'id'),
coalesce(max(id)+1, 1),
false
) FROM corpus;
""")
)
if with_columns is True:
for col in copy.deepcopy(DB_CORPORA[corpus]["columns"]):
db.session.add(col)
Expand All @@ -161,4 +172,6 @@ def add_corpus(
index += 1

db.session.commit()


return corpus_object
22 changes: 0 additions & 22 deletions tests/test_selenium/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,18 +309,6 @@ def create_temp_example_file(self):

def addCorpus(self, corpus, cl=True, *args, **kwargs):
corpus = add_corpus(corpus.lower(), db, cl, *args, **kwargs)
if self.db.engine.dialect.name == "postgresql":
self.db.session.execute(
text("""SELECT setval(
pg_get_serial_sequence('corpus', 'id'),
coalesce(max(id)+1, 1),
false
) FROM corpus;
""")
)

# https://stackoverflow.com/questions/37970743/postgresql-unique-violation-7-error-duplicate-key-value-violates-unique-const/37972960#37972960

if self.AUTO_LOG_IN and not kwargs.get("no_corpus_user", False):
self.addCorpusUser(corpus.name, self.app.config['ADMIN_EMAIL'], is_owner=kwargs.get("is_owner", True))
self.driver.get(self.get_server_url())
Expand All @@ -337,16 +325,6 @@ def addCorpusUser(self, corpus_name, email, is_owner=False, _commit=True):

def addControlLists(self, cl_name, *args, **kwargs):
cl = add_control_lists(cl_name, db, *args, **kwargs)
# https://stackoverflow.com/questions/37970743/postgresql-unique-violation-7-error-duplicate-key-value-violates-unique-const/37972960#37972960
if self.db.engine.dialect.name == "postgresql":
self.db.session.execute(
text("""SELECT setval(
pg_get_serial_sequence('control_lists', 'id'),
coalesce(max(id)+1, 1),
false
) FROM control_lists;
""")
)
self.driver.get(self.get_server_url())
if self.AUTO_LOG_IN and not kwargs.get("no_corpus_user", False):
self.addControlListsUser(cl.name, self.app.config['ADMIN_EMAIL'], is_owner=kwargs.get("is_owner", True))
Expand Down

0 comments on commit 54c5999

Please sign in to comment.