mdbq 4.0.46__py3-none-any.whl → 4.0.47__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
mdbq/__version__.py CHANGED
@@ -1 +1 @@
1
- VERSION = '4.0.46'
1
+ VERSION = '4.0.47'
mdbq/mysql/uploader.py CHANGED
@@ -14,6 +14,7 @@ from dbutils.pooled_db import PooledDB
14
14
  import sys
15
15
  from decimal import Decimal, InvalidOperation
16
16
  import math
17
+ import json
17
18
 
18
19
  warnings.filterwarnings('ignore')
19
20
  logger = mylogger.MyLogger(
@@ -630,7 +631,6 @@ class MySQLUploader:
630
631
  if 'json' in column_type_lower:
631
632
  if isinstance(value, (dict, list)):
632
633
  try:
633
- import json
634
634
  return json.dumps(value, ensure_ascii=False)
635
635
  except (TypeError, ValueError) as e:
636
636
  logger.error(f"JSON序列化失败: {e}", {"库": db_name, "表": table_name, "列": col_name, "值": value})
@@ -638,7 +638,6 @@ class MySQLUploader:
638
638
  elif isinstance(value, str):
639
639
  # 验证字符串是否为有效的JSON
640
640
  try:
641
- import json
642
641
  json.loads(value)
643
642
  return value
644
643
  except (TypeError, ValueError) as e:
@@ -743,7 +742,15 @@ class MySQLUploader:
743
742
  except (AttributeError, IndexError):
744
743
  pass
745
744
  return str_value
746
- return value
745
+
746
+ # 兜底处理:确保所有返回值都是基本数据类型
747
+ if isinstance(value, (dict, list)):
748
+ try:
749
+ return json.dumps(value, ensure_ascii=False)
750
+ except (TypeError, ValueError):
751
+ return str(value)
752
+ else:
753
+ return str(value)
747
754
 
748
755
  @_execute_with_retry
749
756
  def _get_table_columns(self, db_name: str, table_name: str) -> Dict[str, str]:
@@ -1551,6 +1558,16 @@ class MySQLUploader:
1551
1558
  return 1000
1552
1559
  else:
1553
1560
  return 2000
1561
+
1562
+ def ensure_basic_type(value):
1563
+ """确保值是基本数据类型,如果是字典或列表则转换为字符串"""
1564
+ if isinstance(value, (dict, list)):
1565
+ try:
1566
+ return json.dumps(value, ensure_ascii=False)
1567
+ except (TypeError, ValueError):
1568
+ return str(value)
1569
+ return value
1570
+
1554
1571
  batch_size = get_optimal_batch_size(len(data))
1555
1572
  all_columns = [col for col in set_typ.keys() if col.lower() != 'id']
1556
1573
  total_inserted = 0
@@ -1563,10 +1580,10 @@ class MySQLUploader:
1563
1580
  batch = data[i:i + batch_size]
1564
1581
  values_list = []
1565
1582
  for row in batch:
1566
- values = [row.get(col) for col in all_columns]
1583
+ values = [ensure_basic_type(row.get(col)) for col in all_columns]
1567
1584
  if check_duplicate and not update_on_duplicate:
1568
1585
  dup_cols = duplicate_columns if duplicate_columns else [col for col in all_columns if col.lower() not in self.base_excute_col]
1569
- values += [row.get(col) for col in dup_cols]
1586
+ values += [ensure_basic_type(row.get(col)) for col in dup_cols]
1570
1587
  values_list.append(values)
1571
1588
  try:
1572
1589
  cursor.executemany(sql, values_list)
@@ -1599,10 +1616,10 @@ class MySQLUploader:
1599
1616
  batch = data[i:i + hybrid_n]
1600
1617
  for row in batch:
1601
1618
  try:
1602
- values = [row.get(col) for col in all_columns]
1619
+ values = [ensure_basic_type(row.get(col)) for col in all_columns]
1603
1620
  if check_duplicate and not update_on_duplicate:
1604
1621
  dup_cols = duplicate_columns if duplicate_columns else [col for col in all_columns if col.lower() not in self.base_excute_col]
1605
- values += [row.get(col) for col in dup_cols]
1622
+ values += [ensure_basic_type(row.get(col)) for col in dup_cols]
1606
1623
  cursor.execute(sql, values)
1607
1624
  affected = cursor.rowcount if cursor.rowcount is not None else 0
1608
1625
  if update_on_duplicate:
@@ -1627,10 +1644,10 @@ class MySQLUploader:
1627
1644
  else: # row模式
1628
1645
  for row in data:
1629
1646
  try:
1630
- values = [row.get(col) for col in all_columns]
1647
+ values = [ensure_basic_type(row.get(col)) for col in all_columns]
1631
1648
  if check_duplicate and not update_on_duplicate:
1632
1649
  dup_cols = duplicate_columns if duplicate_columns else [col for col in all_columns if col.lower() not in self.base_excute_col]
1633
- values += [row.get(col) for col in dup_cols]
1650
+ values += [ensure_basic_type(row.get(col)) for col in dup_cols]
1634
1651
  cursor.execute(sql, values)
1635
1652
  affected = cursor.rowcount if cursor.rowcount is not None else 0
1636
1653
  if update_on_duplicate:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mdbq
3
- Version: 4.0.46
3
+ Version: 4.0.47
4
4
  Home-page: https://pypi.org/project/mdbq
5
5
  Author: xigua,
6
6
  Author-email: 2587125111@qq.com
@@ -1,5 +1,5 @@
1
1
  mdbq/__init__.py,sha256=Il5Q9ATdX8yXqVxtP_nYqUhExzxPC_qk_WXQ_4h0exg,16
2
- mdbq/__version__.py,sha256=_sPwKl25zozCOVLAfNKDLrJOiNvhHbBB2Oh22FfZsGk,18
2
+ mdbq/__version__.py,sha256=VOS7S7alTl8woUwMDIW96XJ-1hJ6jsjObiRC2Q4yLis,18
3
3
  mdbq/aggregation/__init__.py,sha256=EeDqX2Aml6SPx8363J-v1lz0EcZtgwIBYyCJV6CcEDU,40
4
4
  mdbq/aggregation/query_data.py,sha256=gQUcdrK0QCA0nEBkRA9zBieRWqSnkvpV5Eb-hXKw9Y8,170094
5
5
  mdbq/log/__init__.py,sha256=Mpbrav0s0ifLL7lVDAuePEi1hJKiSHhxcv1byBKDl5E,15
@@ -11,7 +11,7 @@ mdbq/mysql/deduplicator.py,sha256=AB3gL7ZwhcmzGHSu4UY4M6YZVPFZ2wlAN3BCcwAhegQ,73
11
11
  mdbq/mysql/mysql.py,sha256=pDg771xBugCMSTWeskIFTi3pFLgaqgyG3smzf-86Wn8,56772
12
12
  mdbq/mysql/s_query.py,sha256=1wJ3HVjHEF6FA-bVeeesRlsf73CZSvVTEQ51CF1OsE4,46786
13
13
  mdbq/mysql/unique_.py,sha256=MaztT-WIyEQUs-OOYY4pFulgHVcXR1BfCy3QUz0XM_U,21127
14
- mdbq/mysql/uploader.py,sha256=NKwuBZcm4597_3gnY9M5m-jnD5joaVjf28twfQfP_jE,87955
14
+ mdbq/mysql/uploader.py,sha256=Y5gCXuhZR-Oo89xaU4wRlcrzDtarABEyJLt43GvDhcI,88718
15
15
  mdbq/other/__init__.py,sha256=jso1oHcy6cJEfa7udS_9uO5X6kZLoPBF8l3wCYmr5dM,18
16
16
  mdbq/other/download_sku_picture.py,sha256=X66sVdvVgzoNzmgVJyPtd7bjEvctEKtLPblEPF65EWc,46940
17
17
  mdbq/other/error_handler.py,sha256=4p5haAXSY-P78stp4Xwo_MwAngWYqyKj5ogWIuYXMeY,12631
@@ -25,7 +25,7 @@ mdbq/redis/__init__.py,sha256=YtgBlVSMDphtpwYX248wGge1x-Ex_mMufz4-8W0XRmA,12
25
25
  mdbq/redis/getredis.py,sha256=vpBuNc22uj9Vr-_Dh25_wpwWM1e-072EAAIBdB_IpL0,23494
26
26
  mdbq/spider/__init__.py,sha256=RBMFXGy_jd1HXZhngB2T2XTvJqki8P_Fr-pBcwijnew,18
27
27
  mdbq/spider/aikucun.py,sha256=XptHjGzbout9IYzWAOQUpMMV5qEgLTU8pL1ZGt8oNEA,21868
28
- mdbq-4.0.46.dist-info/METADATA,sha256=gwdYseVCsqG4wlrM-Upti194tEpmc1PB7TKshTGKI30,364
29
- mdbq-4.0.46.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
30
- mdbq-4.0.46.dist-info/top_level.txt,sha256=2FQ-uLnCSB-OwFiWntzmwosW3X2Xqsg0ewh1axsaylA,5
31
- mdbq-4.0.46.dist-info/RECORD,,
28
+ mdbq-4.0.47.dist-info/METADATA,sha256=QhfkX2DquhukBOdBvFoJMZfRoZ6Hcja6VWQxaZGcPz0,364
29
+ mdbq-4.0.47.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
30
+ mdbq-4.0.47.dist-info/top_level.txt,sha256=2FQ-uLnCSB-OwFiWntzmwosW3X2Xqsg0ewh1axsaylA,5
31
+ mdbq-4.0.47.dist-info/RECORD,,
File without changes