Skip to content

Commit

Permalink
(#1632) fix for unicode chars in seed files
Browse files Browse the repository at this point in the history
  • Loading branch information
drewbanin committed Jul 30, 2019
1 parent 52c9234 commit 7001afb
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/dbt/clients/agate_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ def from_csv(abspath):
with dbt.compat.open_file(abspath) as fp:
if fp.read(1) != BOM:
fp.seek(0)
return agate.Table.from_csv(fp, column_types=DEFAULT_TYPE_TESTER)

file_buf = dbt.compat.read_into_buffer(fp)
return agate.Table.from_csv(file_buf, column_types=DEFAULT_TYPE_TESTER)
14 changes: 14 additions & 0 deletions core/dbt/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@
from SocketServer import TCPServer
from Queue import PriorityQueue, Empty as QueueEmpty
from thread import get_ident
from StringIO import StringIO
else:
from http.server import SimpleHTTPRequestHandler
from socketserver import TCPServer
from queue import PriorityQueue, Empty as QueueEmpty
from threading import get_ident
from io import StringIO


def to_unicode(s):
Expand Down Expand Up @@ -98,6 +100,18 @@ def open_file(path):
return open(path, encoding='utf-8')


def read_into_buffer(fp):
buf = StringIO()

if WHICH_PYTHON == 2:
buf.write(fp.read().encode('utf-8'))
else:
buf.write(fp.read())

buf.seek(0)
return buf


if WHICH_PYTHON == 2:
# In python 2, classmethod and staticmethod do not allow setters, so you
# can't treat classmethods as first-class objects like you can regular
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
id
Uh – Oh
22 changes: 22 additions & 0 deletions test/integration/005_simple_seed_test/test_simple_seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,25 @@ def test_simple_seed(self):
results = self.run_dbt(["seed"])
self.assertEqual(len(results), 1)
self.assertTablesEqual("seed_bom", "seed_expected")


class TestSimpleSeedWithUnicode(DBTIntegrationTest):

@property
def schema(self):
return "simple_seed_005"

@property
def models(self):
return "models"

@property
def project_config(self):
return {
"data-paths": ['data-unicode']
}

@use_profile('postgres')
def test_simple_seed(self):
results = self.run_dbt(["seed"])
self.assertEqual(len(results), 1)

0 comments on commit 7001afb

Please sign in to comment.