import sys import os import time import logging # Ensure we can import from backend sys.path.append(os.path.join(os.getcwd(), 'backend')) # Setup logging logging.basicConfig(level=logging.INFO) from app.clients.bloomberg_client import BloombergClient def test_bdp_options_injection(): print("Initializing BloombergClient...") client = BloombergClient() ticker = "6301 JP Equity" code = """ import sys try: if 'bquery' not in globals(): import bquery except ImportError: pass ticker = "{ticker}" fields = ["CUR_MKT_CAP", "PX_LAST"] print(f"--- Option Injection Test for {{ticker}} ---") def get_val_via_options(custom_overrides, desc): try: # Pass overrides=None, pass custom overrides via options # Escape braces for format string by doubling them df = bquery.bdp([ticker], fields, overrides=None, options={{'overrides': custom_overrides}}) if not df.empty: print(f"--- {{desc}} ---") for col in df.columns: print(f" {{col}}: {{df.iloc[0][col]}}") print(f" Sent: {{custom_overrides}}") else: print(f"{{desc}} Empty") except Exception as e: print(f"{{desc}} Error: {{e}}") # 1. Direct fieldId (No wrapper) get_val_via_options([{{'fieldId': 'CURRENCY', 'value': 'USD'}}], "Try1_Direct_Dict") # 2. Wrapped in 'overrides' (Same as current impl) get_val_via_options([{{'overrides': {{'fieldId': 'CURRENCY', 'value': 'USD'}}}}], "Try2_Wrapped_Overrides") # 3. Wrapped in 'override' (Singular) get_val_via_options([{{'override': {{'fieldId': 'CURRENCY', 'value': 'USD'}}}}], "Try3_Wrapped_Override") """ formatted_code = code.format(ticker=ticker) print(f"Executing remote logic for {ticker}...") output = client.execute_remote_code(formatted_code) print("Remote Output:") print(output) if __name__ == "__main__": test_bdp_options_injection()