fix: replace 7 bare except clauses with except Exception in server/query.py#7300
fix: replace 7 bare except clauses with except Exception in server/query.py#7300harshadkhetpal wants to merge 1 commit intovoxel51:developfrom
Conversation
7 bare except: clauses replaced with Exception or BaseException based on whether the block re-raises.
|
Thanks for opening this pull request, @harshadkhetpal! 🎉 A maintainer will review your changes soon. In the meantime, please ensure:
Helpful resources: |
WalkthroughThis pull request replaces seven bare Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@fiftyone/server/query.py`:
- Around line 675-678: The local variable named `type` shadows Python's builtin;
rename it (e.g., to `run_type`) wherever it's assigned and used around the brain
method config retrieval (the expression brain_method.config.type().value and its
subsequent fallback to None) and update all usages (including the places noted
near the assignment and later use around the code that references this value) so
references match the new name; ensure imports or other symbols are unaffected
and run linters/tests to confirm Ruff A001 is resolved.
🪄 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: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 25d18e74-2a3f-456f-9958-6fdd48e8d9d4
📒 Files selected for processing (1)
fiftyone/server/query.py
| try: | ||
| type = brain_method.config.type().value | ||
| except: | ||
| except Exception: | ||
| type = None |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify remaining builtin-shadowing assignments in this file
rg -nP -C2 '\btype\s*=' fiftyone/server/query.pyRepository: voxel51/fiftyone
Length of output: 284
🏁 Script executed:
#!/bin/bash
# Get broader context around lines 675-678, including any setattr calls
sed -n '670,690p' fiftyone/server/query.py | cat -nRepository: voxel51/fiftyone
Length of output: 834
🏁 Script executed:
#!/bin/bash
# Search for the setattr call mentioned in the review
rg -n 'setattr.*type' fiftyone/server/query.py | head -20Repository: voxel51/fiftyone
Length of output: 118
🏁 Script executed:
#!/bin/bash
# Get the complete context of this function block to see all type variable usages
sed -n '674,710p' fiftyone/server/query.py | cat -nRepository: voxel51/fiftyone
Length of output: 1385
🏁 Script executed:
#!/bin/bash
# Verify there are no other occurrences of type variable in this function scope
# and confirm the proposed fix covers all usages
rg -n '\btype\b' fiftyone/server/query.py | grep -A2 -B2 '67[0-9]\|69[0-9]'Repository: voxel51/fiftyone
Length of output: 238
Rename local type to avoid builtin shadowing.
type shadows Python's builtin and is flagged by Ruff (A001). Rename it (e.g., run_type) at lines 676, 678, and 692 where the variable is assigned and used.
Proposed fix
try:
- type = brain_method.config.type().value
+ run_type = brain_method.config.type().value
except Exception:
- type = None
+ run_type = None
try:
max_k = brain_method.config.max_k()
except Exception:
max_k = None
try:
supports_least_similarity = (
brain_method.config.supports_least_similarity()
)
except Exception:
supports_least_similarity = None
- setattr(brain_method.config, "type", type)
+ setattr(brain_method.config, "type", run_type)
setattr(brain_method.config, "max_k", max_k)🧰 Tools
🪛 Ruff (0.15.7)
[error] 676-676: Variable type is shadowing a Python builtin
(A001)
[warning] 677-677: Do not catch blind exception: Exception
(BLE001)
[error] 678-678: Variable type is shadowing a Python builtin
(A001)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@fiftyone/server/query.py` around lines 675 - 678, The local variable named
`type` shadows Python's builtin; rename it (e.g., to `run_type`) wherever it's
assigned and used around the brain method config retrieval (the expression
brain_method.config.type().value and its subsequent fallback to None) and update
all usages (including the places noted near the assignment and later use around
the code that references this value) so references match the new name; ensure
imports or other symbols are unaffected and run linters/tests to confirm Ruff
A001 is resolved.
Summary
Replace 7 bare
except:clauses withexcept Exception:infiftyone/server/query.py.Bare
except:catches all exceptions includingSystemExit,KeyboardInterrupt, andGeneratorExit. In a server query module these broad catches can silently swallow signals that should terminate the process.except Exception:is the correct form for "catch any non-fatal error."All 7 changes follow this pattern:
Affected lines: 122, 144, 520, 621 (and 3 more)
Testing
No behavior change — correctness/style fix only. All exception-swallowing blocks continue to catch non-fatal errors as intended while allowing
KeyboardInterruptto propagate correctly.Summary by CodeRabbit