Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for unicode chars in seed files #1644

Merged
merged 2 commits into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions core/dbt/clients/agate_helper.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
from codecs import BOM_UTF8

import dbt.compat

import agate

BOM = BOM_UTF8.decode('utf-8') # '\ufeff'

DEFAULT_TYPE_TESTER = agate.TypeTester(types=[
agate.data_types.Number(null_values=('null', '')),
agate.data_types.TimeDelta(null_values=('null', '')),
Expand Down Expand Up @@ -46,7 +42,7 @@ def as_matrix(table):


def from_csv(abspath):
with dbt.compat.open_file(abspath) as fp:
if fp.read(1) != BOM:
with dbt.compat.open_seed_file(abspath) as fp:
if fp.read(len(dbt.compat.BOM_UTF8)) != dbt.compat.BOM_UTF8:
fp.seek(0)
return agate.Table.from_csv(fp, 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 @@ -98,6 +98,20 @@ def open_file(path):
return open(path, encoding='utf-8')


if WHICH_PYTHON == 2:
BOM_UTF8 = codecs.BOM_UTF8
else:
BOM_UTF8 = codecs.BOM_UTF8.decode('utf-8')


def open_seed_file(path):
if WHICH_PYTHON == 2:
fp = open(path, 'Urb')
else:
fp = open(path, encoding='utf-8')
return fp


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)