mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 09:51:11 -05:00
Stop blank strings being inserted as inbound numbers
We had an inbound number in the database with a value of ''. This could happen if there are blank lines in the inbound numbers file we use for the `insert-inbound-numbers` command. To avoid this happening again, the command now calls `.strip()` on each line of the file and only inserts a row if the result is truthy (i.e. not '').
This commit is contained in:
@@ -246,14 +246,15 @@ def fix_notification_statuses_not_in_sync():
|
||||
one number per line. The number must have the format of 07... not 447....""")
|
||||
def insert_inbound_numbers_from_file(file_name):
|
||||
print("Inserting inbound numbers from {}".format(file_name))
|
||||
file = open(file_name)
|
||||
sql = "insert into inbound_numbers values('{}', '{}', 'mmg', null, True, now(), null);"
|
||||
with open(file_name) as file:
|
||||
sql = "insert into inbound_numbers values('{}', '{}', 'mmg', null, True, now(), null);"
|
||||
|
||||
for line in file:
|
||||
print(line)
|
||||
db.session.execute(sql.format(uuid.uuid4(), line.strip()))
|
||||
db.session.commit()
|
||||
file.close()
|
||||
for line in file:
|
||||
line = line.strip()
|
||||
if line:
|
||||
print(line)
|
||||
db.session.execute(sql.format(uuid.uuid4(), line))
|
||||
db.session.commit()
|
||||
|
||||
|
||||
@notify_command(name='replay-create-pdf-for-templated-letter')
|
||||
|
||||
Reference in New Issue
Block a user