Skip to content

Conversation

@cfsmp3
Copy link
Contributor

@cfsmp3 cfsmp3 commented Dec 28, 2025

Summary

This PR fixes multiple server errors identified from analyzing production logs in /tmp/sp:

  • Null check in queue_test() - Prevents crash when Test record is missing
  • CommitStatus subscript fix - Use attribute access instead of dict syntax for PyGithub objects
  • TempFiles directory creation - Ensure directories exist before file operations
  • Login redirect fix - Gracefully handle BuildError when endpoint requires parameters

Issues Fixed

1. AttributeError: 'NoneType' object has no attribute 'id' in queue_test

  • Location: mod_ci/controllers.py:1305
  • Cause: queue_test() assumed Test record always exists
  • Fix: Add null check before accessing platform_test.id

2. TypeError: 'CommitStatus' object is not subscriptable

  • Location: mod_ci/controllers.py:1498
  • Cause: Code used status["context"] but PyGithub returns objects, not dicts
  • Fix: Changed to status.context attribute access

3. FileNotFoundError in progress_reporter

  • Location: mod_ci/controllers.py:2135-2150
  • Cause: TempFiles and TestResults directories may not exist
  • Fix: Added os.makedirs(..., exist_ok=True) before file operations

4. BuildError: Could not build url for endpoint 'sample.download_sample'

  • Location: mod_auth/controllers.py (login redirect)
  • Cause: Some endpoints require URL parameters that aren't preserved during login redirect
  • Fix: Wrap url_for() in try/except, redirect to home page on BuildError

Files Changed

  • mod_ci/controllers.py - Null check, CommitStatus fix, directory creation
  • mod_auth/controllers.py - Graceful error handling for login redirects

Test plan

  • Verify login redirect tests pass
  • Verify existing CI tests pass
  • Deploy and monitor logs for reduced 500 errors

🤖 Generated with Claude Code

…issing

When queue_test() is called but no matching Test record exists in the
database, platform_test.id would throw AttributeError: 'NoneType' object
has no attribute 'id'.

This can happen when:
- The pull_request webhook was not received or failed
- There's a mismatch in query parameters (commit, platform, test_type, pr_nr)
- A race condition between webhook processing

The fix adds a null check with a descriptive error log before attempting
to access platform_test.id. This prevents the 500 error and provides
debugging information.

Root cause identified from webhook delivery showing 500 error at 18:26:14
on 2025-12-28 when Windows build completed for PR #1920.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Fix 'CommitStatus' object not subscriptable error in start_ci webhook
  handler by using attribute access (status.context) instead of dict
  syntax (status["context"]) for PyGithub CommitStatus objects

- Fix FileNotFoundError in progress_reporter by ensuring TempFiles and
  TestResults directories exist before saving/moving uploaded files

- Fix BuildError for login redirects by storing full URL path instead
  of just endpoint name, preventing crashes when endpoints require
  URL parameters (e.g., sample_id, test_id)

- Add open redirect protection to login handler

- Update tests to match new login redirect behavior

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@cfsmp3 cfsmp3 changed the title fix: Add null check in queue_test to prevent crash when test record missing fix: Address multiple server errors found in production logs Dec 28, 2025
g.log.warning(f'login protected endpoint {request.endpoint} accessed before logging in')
return redirect(url_for('auth.login', next=request.endpoint))
# Store the full URL path instead of just the endpoint name to preserve URL parameters
return redirect(url_for('auth.login', next=request.full_path.rstrip('?')))
Copy link
Member

Choose a reason for hiding this comment

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

If I'm not mistaken this could lead to security risks, are you sure this is safe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed - reverted to using endpoint name and added try/except around url_for() to catch BuildError gracefully. Now redirects to home page when the endpoint requires parameters we don't have.

Comment on lines 231 to 232
if redirect_location and (not redirect_location.startswith('/') or redirect_location.startswith('//')):
redirect_location = ''
Copy link
Member

Choose a reason for hiding this comment

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

This probably does not catch all cases... So I'd rather see the old version and just handle the error more gracefully.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed - reverted to the old approach. Now using try/except around url_for() to catch BuildError and redirect to home page instead. This avoids the security concerns while still preventing the 500 errors.

…path

Address maintainer feedback:
- Revert to using endpoint name in login_required decorator
- Add try/except around url_for() to catch BuildError
- Redirect to home page when endpoint requires parameters we don't have
- Revert tests to original assertions

This is a safer approach than storing the full URL path, which could
introduce security risks.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Update test assertions to account for additional os.path.join and
os.makedirs calls added to ensure TempFiles and TestResults directories
exist before file operations.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@sonarqubecloud
Copy link

@canihavesomecoffee canihavesomecoffee merged commit a06b6db into master Dec 28, 2025
6 checks passed
@cfsmp3 cfsmp3 deleted the fix/queue-test-null-check branch December 29, 2025 08:09
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.

3 participants