Skip to content

Conversation

@aseembits93
Copy link
Contributor

@aseembits93 aseembits93 commented Sep 27, 2025

PR Type

Bug fix


Description

  • Fix env var dict.get usage error

  • Prevent TypeError on missing parameter


Diagram Walkthrough

flowchart LR
  ENV["ENV var CODEFLASH_CFAPI_SERVER"] -- "read via os.environ.get(key, default)" --> CFG["Select CFAPI base URL"]
  CFG -- "local" --> LOCAL["Use http://localhost:3001"]
  CFG -- "otherwise" --> PROD["Use default production endpoint"]
Loading

File Walkthrough

Relevant files
Bug fix
cfapi.py
Fix os.environ.get default argument usage                               

codeflash/api/cfapi.py

  • Replace dict.get default keyword with positional arg
  • Ensure default value "prod" used safely
  • Maintain logic for local vs prod base URL
+1/-1     

Avoid `TypeError: dict.get() takes no keyword arguments` when using env variables with `codeflash optimize`
@github-actions
Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Environment Handling

Confirm that the environment variable value is always a string before calling .lower(); if a non-string (e.g., bytes) can appear in this runtime, an explicit str() cast or try/except could be safer.

if os.environ.get("CODEFLASH_CFAPI_SERVER", "prod").lower() == "local":
    CFAPI_BASE_URL = "http://localhost:3001"
    logger.info(f"Using local CF API at {CFAPI_BASE_URL}.")
    console.rule()
else:

@github-actions
Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Prevent .lower() on non-strings

Guard against missing or non-string environment values that could cause an
AttributeError on .lower(). Coerce the value to str before lowercasing to ensure
robust behavior.

codeflash/api/cfapi.py [29]

-if os.environ.get("CODEFLASH_CFAPI_SERVER", "prod").lower() == "local":
+if str(os.environ.get("CODEFLASH_CFAPI_SERVER", "prod")).lower() == "local":
Suggestion importance[1-10]: 5

__

Why: The existing check calls .lower() on an environment value that could be non-string, risking an AttributeError; coercing to str improves robustness with minimal impact and aligns with the shown line.

Low

@aseembits93 aseembits93 merged commit 36151d0 into main Sep 27, 2025
18 of 21 checks passed
@aseembits93 aseembits93 deleted the fix-dict-get branch September 27, 2025 01:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants