Skip to content

Set HTTP client timeout using FACTURAPI_TIMEOUT environment variable#121

Merged
gmorales96 merged 1 commit into
mainfrom
feature/configurable-http-timeout
Jun 2, 2026
Merged

Set HTTP client timeout using FACTURAPI_TIMEOUT environment variable#121
gmorales96 merged 1 commit into
mainfrom
feature/configurable-http-timeout

Conversation

@gmorales96
Copy link
Copy Markdown
Contributor

@gmorales96 gmorales96 commented Jun 1, 2026

Summary by CodeRabbit

  • Improvements
    • HTTP request timeout is now configurable via the FACTURAPI_TIMEOUT environment variable (default: 10 seconds).

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

Walkthrough

This PR introduces a configurable HTTP timeout for the Facturapi client and bumps the version to 1.0.1. The FACTURAPI_TIMEOUT environment variable (default 10.0 seconds) is read at module load time in facturapi/http/client.py and passed to httpx.Client during initialization. All request/response handling logic remains unchanged. The version is incremented in facturapi/version.py.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding HTTP client timeout configuration via the FACTURAPI_TIMEOUT environment variable, which is the primary modification shown in the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/configurable-http-timeout

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
facturapi/http/client.py (1)

12-12: Note: Timeout is evaluated at module import time.

The FACTURAPI_TIMEOUT constant is read once when the module is imported. Runtime changes to the environment variable will not be reflected until the module is reloaded. This is likely intentional for performance, but worth documenting if this behavior matters for your use case.

🤖 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, FACTURAPI_TIMEOUT is read once at
module import and won't reflect later env var changes; either document this
behavior in the module-level docstring (or README) near FACTURAPI_TIMEOUT to
state it is evaluated at import time, or change to a runtime-read approach
(e.g., replace the constant with a helper function like get_facturapi_timeout()
that reads os.getenv each call) so callers can opt into dynamic behavior;
reference the FACTURAPI_TIMEOUT constant in facturapi/http/client.py when making
the update.
🤖 Prompt for all review comments with 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.

Inline comments:
In `@facturapi/http/client.py`:
- 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.

---

Nitpick comments:
In `@facturapi/http/client.py`:
- Line 12: FACTURAPI_TIMEOUT is read once at module import and won't reflect
later env var changes; either document this behavior in the module-level
docstring (or README) near FACTURAPI_TIMEOUT to state it is evaluated at import
time, or change to a runtime-read approach (e.g., replace the constant with a
helper function like get_facturapi_timeout() that reads os.getenv each call) so
callers can opt into dynamic behavior; reference the FACTURAPI_TIMEOUT constant
in facturapi/http/client.py when making the update.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7e27a2ad-c88d-4023-8e8f-c708959ebf77

📥 Commits

Reviewing files that changed from the base of the PR and between f9f01b5 and c87373a.

📒 Files selected for processing (2)
  • facturapi/http/client.py
  • facturapi/version.py

Comment thread facturapi/http/client.py
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.

@gmorales96 gmorales96 requested a review from rogelioLpz June 1, 2026 22:59
@gmorales96 gmorales96 merged commit eb7af6f into main Jun 2, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants