Skip to content

Commit

Permalink
Fix input modification bug
Browse files Browse the repository at this point in the history
`__extend_row(row)` worked, even though we did not use the output,
because it modified the input variable. It is better to make a copy and
return, and then correctly use that!
  • Loading branch information
agude committed Aug 6, 2021
1 parent 428d2ea commit 9f747ba
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions switrs_to_sqlite/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ def __init__(

def parse_row(self, row):
# The CSV file is malformed, so extend it to avoid KeyErrors
new_row = self.__extend_row(row)
extended_row = self.__extend_row(row)

# Set up list of variables for insertion
values = self.__set_values(row)
values = self.__set_values(extended_row)

return list(values.values())

Expand Down Expand Up @@ -185,9 +185,9 @@ def __extend_row(self, row):
# extent it with "" which maps to null in the conversion. The +1
# converts the final index to length.
extend = (self.parsing_table[-1][0] + 1) - len(row)
row += extend * [""] # "" maps to null
output_row = row + extend * [""] # "" maps to null

return row
return output_row

def insert_statement(self, values):
"""Creates an insert statement used to fill a row in the SQLite table."""
Expand Down
2 changes: 1 addition & 1 deletion switrs_to_sqlite/switrs_to_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


# Library version
__version__ = "3.0.1"
__version__ = "3.0.2"


def main():
Expand Down

0 comments on commit 9f747ba

Please sign in to comment.