Skip to content

Commit

Permalink
More Flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
MattFisher committed Dec 20, 2021
1 parent 72dbbf3 commit a85bd90
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
17 changes: 11 additions & 6 deletions django_redshift_backend/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,9 @@ def get_table_description(self, cursor, table_name):
column_name: (is_nullable, column_default)
for (column_name, is_nullable, column_default) in cursor.fetchall()
}
cursor.execute("SELECT * FROM %s LIMIT 1" % self.connection.ops.quote_name(table_name))
cursor.execute(
"SELECT * FROM %s LIMIT 1" % self.connection.ops.quote_name(table_name)
)
return [
FieldInfo(
name=column.name,
Expand All @@ -599,8 +601,8 @@ def get_table_description(self, cursor, table_name):
scale=column.scale,
null_ok=field_map[column.name][0],
default=field_map[column.name][1],
collation=None, # Redshift doesn't support user-defined collation sequences
# See https://docs.aws.amazon.com/redshift/latest/dg/c_collation_sequences.html
collation=None, # Redshift doesn't support user-defined collation
# https://docs.aws.amazon.com/redshift/latest/dg/c_collation_sequences.html
)
for column in cursor.description
]
Expand Down Expand Up @@ -635,11 +637,14 @@ def get_constraints(self, cursor, table_name):
(conname, conkey, conrelid, contype, used_cols) in cursor.fetchall()
]
table_oid = list(constraint_records)[0][2] # Assuming at least one constraint
attribute_num_to_name_map = self._get_attribute_number_to_name_map_for_table(cursor, table_oid)
attribute_num_to_name_map = self._get_attribute_number_to_name_map_for_table(
cursor, table_oid)

for constraint, conkey, conrelid, kind, used_cols in constraint_records:
constraints[constraint] = {
"columns": [attribute_num_to_name_map[column_id_int] for column_id_int in conkey],
"columns": [
attribute_num_to_name_map[column_id_int] for column_id_int in conkey
],
"primary_key": kind == "p",
"unique": kind in ["p", "u"],
"foreign_key": tuple(used_cols.split(".", 1)) if kind == "f" else None,
Expand All @@ -655,7 +660,7 @@ def get_constraints(self, cursor, table_name):
SELECT
c2.relname,
idx.indrelid,
idx.indkey, -- indkey is of type "int2vector" and returns a space-separated string
idx.indkey, -- type "int2vector", returns space-separated string
idx.indisunique,
idx.indisprimary
FROM
Expand Down
3 changes: 1 addition & 2 deletions tests/test_redshift_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,7 @@ class IntrospectionTest(unittest.TestCase):
u'''SELECT
c2.relname,
idx.indrelid,
idx.indkey,
-- indkey is of type "int2vector" and returns a space-separated string
idx.indkey, -- type "int2vector", returns space-separated string
idx.indisunique,
idx.indisprimary
FROM
Expand Down

0 comments on commit a85bd90

Please sign in to comment.