Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit caa0c6a

Browse files
fix tiny bugs
1 parent 166acb9 commit caa0c6a

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

‎es_sync/__init__.py‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def encode_in_py2(s):
2525
import logging
2626
import shlex
2727
import datetime
28+
import decimal
2829
from lxml.etree import iterparse
2930
from functools import reduce
3031
from pymysqlreplication import BinLogStreamReader
@@ -177,7 +178,9 @@ def _json_serializer(self, obj):
177178
"""
178179
if isinstance(obj, datetime.datetime) or isinstance(obj, datetime.date):
179180
return obj.isoformat()
180-
raise TypeError('Type not serializable')
181+
elif isinstance(obj, decimal.Decimal):
182+
return str(obj)
183+
raise TypeError('Type not serializable for obj {obj}'.format(obj=obj))
181184

182185
def _processor(self, data):
183186
"""
@@ -225,8 +228,11 @@ def _mapper(self, data):
225228
for item in data:
226229
if self.mapping:
227230
for k, v in self.mapping.items():
228-
item['doc'][k] = item['doc'][v]
229-
del item['doc'][v]
231+
try:
232+
item['doc'][k] = item['doc'][v]
233+
del item['doc'][v]
234+
except KeyError:
235+
continue
230236
# print(doc)
231237
yield item
232238

@@ -245,6 +251,8 @@ def _formatter(self, data):
245251
msg=str(e),
246252
item=str(item)))
247253
item['doc'][field] = None
254+
except TypeError as e:
255+
item['doc'][field] = None
248256
# print(item)
249257
yield item
250258

‎test_dump.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__author__ = 'huangweicong'

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /