Skip to content
Merged
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
3 changes: 2 additions & 1 deletion facturapi/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ..version import CLIENT_VERSION

API_HOST = 'www.facturapi.io/v2'
FACTURAPI_TIMEOUT = float(os.getenv('FACTURAPI_TIMEOUT', 10.0))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add validation for the FACTURAPI_TIMEOUT environment variable.

If FACTURAPI_TIMEOUT is set to a non-numeric value, float() will raise a ValueError at module import time, crashing the application. Consider adding error handling to validate the input or provide a clearer error message.

🛡️ Proposed fix to add validation
-FACTURAPI_TIMEOUT = float(os.getenv('FACTURAPI_TIMEOUT', 10.0))
+try:
+    FACTURAPI_TIMEOUT = float(os.getenv('FACTURAPI_TIMEOUT', '10.0'))
+except ValueError:
+    raise ValueError(
+        "FACTURAPI_TIMEOUT environment variable must be a valid number"
+    )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
FACTURAPI_TIMEOUT = float(os.getenv('FACTURAPI_TIMEOUT', 10.0))
try:
FACTURAPI_TIMEOUT = float(os.getenv('FACTURAPI_TIMEOUT', '10.0'))
except ValueError:
raise ValueError(
"FACTURAPI_TIMEOUT environment variable must be a valid number"
)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@facturapi/http/client.py` at line 12, The module-level conversion of
FACTURAPI_TIMEOUT using float(os.getenv('FACTURAPI_TIMEOUT', 10.0)) can raise
ValueError on import if the env var is non-numeric; update the code that defines
FACTURAPI_TIMEOUT to validate the environment value by reading
os.getenv('FACTURAPI_TIMEOUT'), attempting float conversion inside a try/except,
falling back to the default 10.0 on failure (and optionally logging or raising a
clear, descriptive error), and ensure the constant FACTURAPI_TIMEOUT is always
set to a valid float.



class Client:
Expand All @@ -31,7 +32,7 @@ class Client:
client: httpx.Client

def __init__(self) -> None:
self.client = httpx.Client()
self.client = httpx.Client(timeout=FACTURAPI_TIMEOUT)
self.client.headers.update(
{
'User-Agent': f'facturapi-python/{CLIENT_VERSION}',
Expand Down
2 changes: 1 addition & 1 deletion facturapi/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '1.0.0'
__version__ = '1.0.1'
CLIENT_VERSION = __version__
Loading