Skip to content

Commit

Permalink
Merge pull request #17 from koptelovav/patch-1
Browse files Browse the repository at this point in the history
Fix anonymizing error if there is a JSONB column in a table
  • Loading branch information
hkage authored May 5, 2021
2 parents e5bba2c + 74dcc30 commit 4b0e5b1
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pganonymizer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import absolute_import

import csv
import json
import logging
import re
import subprocess
Expand Down Expand Up @@ -189,7 +190,19 @@ def data2csv(data):
"""
buf = StringIO()
writer = csv.writer(buf, delimiter=COPY_DB_DELIMITER, lineterminator='\n', quotechar='~')
[writer.writerow([(x is None and '\\N' or (x.strip() if type(x) == str else x)) for x in row]) for row in data]
for row in data:
row_data = []
for x in row:
if x is None:
val = '\\N'
elif type(x) == str:
val = x.strip()
elif type(x) == dict:
val = json.dumps(x)
else:
val = x
row_data.append(val)
writer.writerow(row_data)
buf.seek(0)
return buf

Expand Down

0 comments on commit 4b0e5b1

Please sign in to comment.