Skip to content

Commit e9d3d9e

Browse files
committed
Merge branch 'btkcodedev/prestashopFix' of https://github.com/airbytehq/airbyte into btkcodedev/prestashopFix
2 parents 1a054e3 + ff0c5ff commit e9d3d9e

File tree

3 files changed

+34
-36
lines changed

3 files changed

+34
-36
lines changed

airbyte-integrations/connectors/source-prestashop/components.py

+32-35
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
33
#
44

5-
from dataclasses import InitVar, dataclass
6-
from typing import Any, List, Mapping, Optional, Tuple
75
import re
6+
from dataclasses import InitVar, dataclass
87
from datetime import datetime as dt
8+
from typing import Any, List, Mapping, Optional, Tuple
99

1010
from airbyte_cdk.sources.declarative.schema import JsonFileSchemaLoader
1111
from airbyte_cdk.sources.declarative.transformations import RecordTransformation
@@ -14,6 +14,7 @@
1414

1515
class ParserError(Exception):
1616
"""Replacement for pendulum's ParserError"""
17+
1718
pass
1819

1920

@@ -48,75 +49,71 @@ def parse(self, text):
4849
Handles various date formats including those with timezone information.
4950
"""
5051
# Reject dates with zeros like '0000-00-00' or '0000-00-00 00:00:00'
51-
if re.match(r'^0+[-]0+[-]0+', text):
52+
if re.match(r"^0+[-]0+[-]0+", text):
5253
raise ParserError("Zero date not allowed")
53-
54+
5455
# Comprehensive list of formats to try
5556
formats = [
5657
# Basic formats
57-
'%Y-%m-%d',
58-
'%Y/%m/%d',
59-
'%d-%m-%Y',
60-
'%d/%m/%Y',
61-
58+
"%Y-%m-%d",
59+
"%Y/%m/%d",
60+
"%d-%m-%Y",
61+
"%d/%m/%Y",
6262
# Date and time formats
63-
'%Y-%m-%d %H:%M:%S',
64-
'%Y-%m-%d %H:%M:%S.%f',
65-
'%Y/%m/%d %H:%M:%S',
66-
'%Y/%m/%d %H:%M:%S.%f',
67-
63+
"%Y-%m-%d %H:%M:%S",
64+
"%Y-%m-%d %H:%M:%S.%f",
65+
"%Y/%m/%d %H:%M:%S",
66+
"%Y/%m/%d %H:%M:%S.%f",
6867
# ISO formats
69-
'%Y-%m-%dT%H:%M:%S',
70-
'%Y-%m-%dT%H:%M:%S.%f',
71-
68+
"%Y-%m-%dT%H:%M:%S",
69+
"%Y-%m-%dT%H:%M:%S.%f",
7270
# With timezone
73-
'%Y-%m-%d %H:%M:%S%z',
74-
'%Y-%m-%d %H:%M:%S.%f%z',
75-
'%Y-%m-%dT%H:%M:%S%z',
76-
'%Y-%m-%dT%H:%M:%S.%f%z',
77-
71+
"%Y-%m-%d %H:%M:%S%z",
72+
"%Y-%m-%d %H:%M:%S.%f%z",
73+
"%Y-%m-%dT%H:%M:%S%z",
74+
"%Y-%m-%dT%H:%M:%S.%f%z",
7875
# Using Z for UTC
79-
'%Y-%m-%dT%H:%M:%SZ',
80-
'%Y-%m-%dT%H:%M:%S.%fZ',
76+
"%Y-%m-%dT%H:%M:%SZ",
77+
"%Y-%m-%dT%H:%M:%S.%fZ",
8178
]
8279

8380
# Try parsing with different formats
8481
for fmt in formats:
8582
try:
8683
# Handle 'Z' timezone indicator for UTC
8784
text_to_parse = text
88-
if fmt.endswith('Z') and not text.endswith('Z'):
85+
if fmt.endswith("Z") and not text.endswith("Z"):
8986
continue
90-
if not fmt.endswith('Z') and text.endswith('Z'):
87+
if not fmt.endswith("Z") and text.endswith("Z"):
9188
text_to_parse = text[:-1] # Remove Z
92-
fmt = fmt + 'Z' if 'Z' not in fmt else fmt
93-
89+
fmt = fmt + "Z" if "Z" not in fmt else fmt
90+
9491
date_obj = dt.strptime(text_to_parse, fmt)
9592
# In pendulum, dates with zero components are rejected
9693
if date_obj.year == 0 or date_obj.month == 0 or date_obj.day == 0:
9794
raise ParserError("Date with zero components")
9895
return date_obj
9996
except ValueError:
10097
continue
101-
98+
10299
# Try ISO format as a last resort
103100
try:
104101
# Replace Z with +00:00 for ISO format parsing
105-
iso_text = text.replace('Z', '+00:00')
106-
102+
iso_text = text.replace("Z", "+00:00")
103+
107104
# For Python < 3.11 compatibility, remove microseconds if they have more than 6 digits
108-
microseconds_match = re.search(r'\.(\d{7,})(?=[+-Z]|$)', iso_text)
105+
microseconds_match = re.search(r"\.(\d{7,})(?=[+-Z]|$)", iso_text)
109106
if microseconds_match:
110107
fixed_micro = microseconds_match.group(1)[:6]
111-
iso_text = iso_text.replace(microseconds_match.group(0), f'.{fixed_micro}')
112-
108+
iso_text = iso_text.replace(microseconds_match.group(0), f".{fixed_micro}")
109+
113110
date_obj = dt.fromisoformat(iso_text)
114111
if date_obj.year == 0 or date_obj.month == 0 or date_obj.day == 0:
115112
raise ParserError("Date with zero components")
116113
return date_obj
117114
except (ValueError, AttributeError):
118115
pass
119-
116+
120117
# If nothing worked, raise the error like pendulum would
121118
raise ParserError(f"Unable to parse: {text}")
122119

airbyte-integrations/connectors/source-prestashop/metadata.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ data:
1010
connectorSubtype: api
1111
connectorType: source
1212
definitionId: d60a46d4-709f-4092-a6b7-2457f7d455f5
13-
dockerImageTag: 1.1.1
13+
dockerImageTag: 1.2.0
1414
dockerRepository: airbyte/source-prestashop
1515
documentationUrl: https://docs.airbyte.com/integrations/sources/prestashop
1616
githubIssueLabel: source-prestashop

docs/integrations/sources/prestashop.md

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ If there are more endpoints you'd like Airbyte to support, please [create an iss
107107

108108
| Version | Date | Pull Request | Subject |
109109
| :------ | :--------- | :-------------------------------------------------------- | :------------------------------------------------------------------------------ |
110+
| 1.2.0 | 2025-03-13 | [55739](https://github.com/airbytehq/airbyte/pull/55739) | Remove pendulum from dependency |
110111
| 1.1.1 | 2025-03-08 | [43831](https://github.com/airbytehq/airbyte/pull/43831) | Update dependencies |
111112
| 1.1.0 | 2025-03-03 | [47016](https://github.com/airbytehq/airbyte/pull/47016) | Migrate to manifest-only format |
112113
| 1.0.4 | 2024-04-19 | [37233](https://github.com/airbytehq/airbyte/pull/37233) | Updating to 0.80.0 CDK |

0 commit comments

Comments
 (0)