Skip to content

Commit 6859116

Browse files
committed
Addressing @squirrelo's comments
1 parent 2fb6558 commit 6859116

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

qiita_db/metadata_template/base_metadata_template.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -797,14 +797,12 @@ def _add_common_extend_steps_to_queue(self, md_template, conn_handler,
797797
existing_samples = curr_samples.intersection(sample_ids)
798798
new_samples = set(sample_ids).difference(existing_samples)
799799

800-
# Check if we are adding new columns
800+
# Check if we are adding new columns, by getting all the columns from
801+
# the database
801802
table_name = self._table_name(self._id)
802-
# Get the required columns from the DB
803803
db_cols = get_table_cols(self._table, conn_handler)
804-
# Remove the sample_id and _id_column columns
805804
db_cols.remove('sample_id')
806805
db_cols.remove(self._id_column)
807-
# Get the columns from the dynamic table and do the union with the db
808806
curr_cols = set(
809807
get_table_cols(table_name, conn_handler)).union(db_cols)
810808
headers = md_template.keys().tolist()
@@ -867,6 +865,10 @@ def _add_common_extend_steps_to_queue(self, md_template, conn_handler,
867865
values = as_python_types(md_template, db_cols)
868866
values.insert(0, new_samples)
869867
values.insert(0, [self._id] * num_samples)
868+
# psycopg2 requires a list of tuples, in which each tuple is a
869+
# tuple of values to use in the string formatting of the query. We
870+
# have all the values in different lists (but in the same order) so
871+
# use zip to create the list of tuples that psycopg2 requires.
870872
values = [v for v in zip(*values)]
871873
sql = """INSERT INTO qiita.{0} ({1}, sample_id, {2})
872874
VALUES (%s, %s, {3})""".format(

0 commit comments

Comments
 (0)