-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_minimal_insert.py
More file actions
71 lines (59 loc) · 2.31 KB
/
test_minimal_insert.py
File metadata and controls
71 lines (59 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
"""
Minimal test script to determine exact issue with market_data insertion
"""
import logging
import sys
from pathlib import Path
# Add project root to path
current_dir = Path(__file__).parent
sys.path.append(str(current_dir))
# Moved import to top (E402 fix)
from src.database.client import DatabaseClient
# Configure detailed logging
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", # Line break (E501 fix)
)
logger = logging.getLogger(__name__)
def get_existing_record():
"""Inspect a real record from the database"""
db = DatabaseClient()
response = db.client.table("market_data").select("*").limit(1).execute()
if response.data:
logger.info(f"Sample record from DB: {response.data[0]}")
# Print types of each field
for key, value in response.data[0].items():
logger.info(f"Field '{key}': {type(value)}")
return response.data[0]
return None
def test_direct_api_call():
"""Test direct API call with most minimal data possible"""
db = DatabaseClient()
# Create a minimal record
minimal_record = {
"asset_id": 1,
"timestamp": "2025-01-01T12:00:00.000Z",
"price_usd": 50000.0,
"additional_data": {}, # Empty object, not a string
}
try:
# Direct API call to get detailed error
logger.info(f"Attempting direct API call with: {minimal_record}")
response = db.client.table("market_data").insert(minimal_record).execute()
logger.info(f"Success! Response: {response.data}")
return True
except Exception as e:
error_msg = str(e)
logger.error(f"Error details: {error_msg}")
# Try to parse the error message for more details
if "column" in error_msg.lower() and "not exist" in error_msg.lower():
logger.error("Column name mismatch detected!") # Line break (E501 fix)
if "violates" in error_msg.lower() and "constraint" in error_msg.lower():
logger.error("Constraint violation detected!") # Line break (E501 fix)
return False
if __name__ == "__main__":
logger.info("Fetching sample record from database...")
existing = get_existing_record()
logger.info("\nTesting most minimal possible insert...")
test_direct_api_call()