Skip to content
Draft
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
2 changes: 1 addition & 1 deletion services/listing_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def create_listing_draft(

# Strip markdown
clean_json = response_text
json_match = re.search(r'```(?:json)?\s*(\{.*?\})\s*```', response_text, re.DOTALL)
json_match = re.search(r'```(?:json)?\s*({.*?})\s*```', response_text, re.DOTALL)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The original code used a raw string literal (r'...'), so \{ is not treated as an invalid Python escape sequence and does not trigger a SyntaxWarning in Python 3.12.

In regular expressions, { is a reserved metacharacter used for quantifiers (e.g., {m,n}). Although Python's re module currently falls back to treating { as a literal when it is not followed by a valid quantifier pattern, relying on this behavior is discouraged. Escaping it as \{ is the standard and robust way to match a literal { and avoids potential parsing ambiguity.

It is recommended to revert this change to keep the regex robust and clear.

Suggested change
json_match = re.search(r'```(?:json)?\s*({.*?})\s*```', response_text, re.DOTALL)
json_match = re.search(r'```(?:json)?\s*(\{.*?\})\s*```', response_text, re.DOTALL)

if json_match:
clean_json = json_match.group(1)
else:
Expand Down
7 changes: 7 additions & 0 deletions tests/test_listing_reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,14 @@ def test_generate_title_empty_data(self):
self.assertEqual(title, "Item")

class TestListingReconstruction(unittest.TestCase):
@patch.dict(os.environ, {'GOOGLE_API_KEY': 'test_key'})
def setUp(self):
# We need to explicitly initialize listing_engine and ebay_integration for app_enhanced to not fail
import app_enhanced
from services.listing_synthesis import ListingSynthesisEngine
from services.ebay_integration import eBayIntegration
app_enhanced.listing_engine = ListingSynthesisEngine()
app_enhanced.ebay_integration = eBayIntegration(use_sandbox=True)
# Setup a test database
self.db_path = 'test_listings.db'
if os.path.exists(self.db_path):
Expand Down
Loading