Skip to content

fix: Use reauth_entry.data instead of undefined self.data in reauth flow#318

Merged
GuyKh merged 2 commits intomainfrom
fix/reauth-flow-data-bug
Feb 15, 2026
Merged

fix: Use reauth_entry.data instead of undefined self.data in reauth flow#318
GuyKh merged 2 commits intomainfrom
fix/reauth-flow-data-bug

Conversation

@GuyKh
Copy link
Owner

@GuyKh GuyKh commented Feb 15, 2026

User description

Summary

Fix a bug in the re-authentication flow where self.data was used instead of self.reauth_entry.data.

Bug

In async_step_reauth_confirm, when the client wasn't initialized yet, the code attempted to access self.data[CONF_USER_ID], but self.data is never set during the reauth flow. This would cause a KeyError.

Fix

Changed line 284 from:

self.data[CONF_USER_ID]

to:

self.reauth_entry.data[CONF_USER_ID]

Also added an assertion to ensure self.reauth_entry is not None before accessing it.


PR Type

Bug fix


Description

  • Fix KeyError in reauth flow by using correct data source

  • Replace undefined self.data with self.reauth_entry.data

  • Add assertion to ensure self.reauth_entry is not None

  • Improve code reliability during re-authentication process


Diagram Walkthrough

flowchart LR
  A["async_step_reauth_confirm"] -->|"client not initialized"| B["Access user ID"]
  B -->|"Before: self.data"| C["KeyError - undefined"]
  B -->|"After: self.reauth_entry.data"| D["Correct data source"]
  D --> E["IecClient initialization"]
Loading

File Walkthrough

Relevant files
Bug fix
config_flow.py
Fix reauth flow data access in async_step_reauth_confirm 

custom_components/iec/config_flow.py

  • Fixed bug where self.data[CONF_USER_ID] was accessed but self.data is
    never set during reauth flow
  • Changed to use self.reauth_entry.data[CONF_USER_ID] to access the
    correct data source
  • Added assertion to verify self.reauth_entry is not None before
    accessing its data
  • Reformatted IecClient instantiation for better readability
+3/-1     

The reauth flow was trying to access self.data[CONF_USER_ID] but
self.data is never set during reauth, causing a KeyError. Fixed by
using self.reauth_entry.data[CONF_USER_ID] instead.
@qodo-code-review
Copy link

ⓘ You are approaching your monthly quota for Qodo. Upgrade your plan

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

🔴
Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status:
Assertion as control: The new assert self.reauth_entry is not None can raise an unhandled AssertionError instead
of gracefully aborting or handling a missing reauth entry.

Referred Code
if not client:
    assert self.reauth_entry is not None
    self.client = IecClient(
        self.reauth_entry.data[CONF_USER_ID],
        async_create_clientsession(self.hass),
    )

Learn more about managing compliance generic rules or creating your own custom rules

Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-code-review
Copy link

ⓘ You are approaching your monthly quota for Qodo. Upgrade your plan

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Check user ID presence

Add a check to ensure CONF_USER_ID exists in self.reauth_entry.data before
accessing it, and abort the flow gracefully if it's missing to prevent a
KeyError.

custom_components/iec/config_flow.py [284-287]

+if CONF_USER_ID not in self.reauth_entry.data:
+    return self.async_abort(reason="missing_user_id")
 self.client = IecClient(
     self.reauth_entry.data[CONF_USER_ID],
     async_create_clientsession(self.hass),
 )
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies a potential KeyError if CONF_USER_ID is missing from the entry data and proposes adding a check to handle this case gracefully, improving the robustness of the reauthentication flow.

Medium
General
Remove redundant assertion for cleaner code

Remove the redundant assert self.reauth_entry is not None since an equivalent
assertion already exists at the start of the async_step_reauth_confirm method.

custom_components/iec/config_flow.py [282-288]

 if not client:
-    assert self.reauth_entry is not None
     self.client = IecClient(
         self.reauth_entry.data[CONF_USER_ID],
         async_create_clientsession(self.hass),
     )
     client = self.client
  • Apply / Chat
Suggestion importance[1-10]: 3

__

Why: The suggestion correctly identifies a redundant assert statement, as the check is already performed at the beginning of the function. Removing it improves code cleanliness.

Low
  • More

@GuyKh GuyKh merged commit 35f8877 into main Feb 15, 2026
5 checks passed
@GuyKh GuyKh deleted the fix/reauth-flow-data-bug branch February 15, 2026 13:48
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.

1 participant