Skip to content

Test 5 mini - #93

Closed
unnat-deepsource wants to merge 2 commits into
masterfrom
test-5-mini
Closed

Test 5 mini#93
unnat-deepsource wants to merge 2 commits into
masterfrom
test-5-mini

Conversation

@unnat-deepsource

Copy link
Copy Markdown
Collaborator

No description provided.

@unnat-deepsource

Copy link
Copy Markdown
Collaborator Author

@deepsourcebot review

@deepsource-development

deepsource-development Bot commented Apr 20, 2026

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in 9d1323c...f634b03 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade  

Focus Area: Reliability
Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
Python Apr 20, 2026 8:40a.m. Review ↗
Secrets Apr 20, 2026 8:40a.m. Review ↗

Comment thread app/inventory.py
from __future__ import annotations

import logging
from dataclasses import dataclass, field

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unused `field` import increases code clutter


The field object imported from the dataclasses module is not used anywhere in the file. This adds unnecessary clutter to the code and can cause confusion for maintainers. It might also slightly impact static analysis performance.
Remove the unused field import to clean up and simplify the codebase.

Comment thread app/inventory.py
product.quantity += quantity
return product

def get_low_stock(self, categories: list[str] = []) -> list[Product]:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Mutable default `list` causes shared state across calls


The method get_low_stock uses a mutable default argument categories set to an empty list, which persists across all calls. Mutations to this list in one call affect subsequent calls, potentially causing incorrect behavior or bugs.

Replace the mutable default with None and initialize the list inside the method to ensure each call receives a fresh list object, avoiding shared mutable state issues.

Comment thread app/inventory.py
]
return low

def bulk_update_prices(self, updates: dict[str, float] = {}) -> int:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Mutable default `updates` dict causes state persistence


The bulk_update_prices method has a mutable default argument updates set as an empty dictionary {}. This dictionary is created once at function definition and reused, causing any changes to persist across calls and corrupt behavior.

Replace the default value with None and initialize a new dictionary inside the method if updates is None to avoid shared mutable state.

Comment thread app/inventory.py
if normalized in p.name.lower()
]

def export_snapshot(self, fields: list[str] = []) -> list[dict]:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Mutable default `fields=[]` causes shared state bugs


The fields argument defaults to an empty list [], which is mutable and evaluated once at function definition. This causes all calls without an explicit fields argument to share the same list, leading to unpredictable side effects such as accumulating values.

Replace the default with None and inside the function initialize the list if fields is None. This ensures each call gets a fresh list, preventing shared state issues.

Comment thread app/inventory.py
if fields:
entry = {k: v for k, v in entry.items() if k in fields}
snapshot.append(entry)
except:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bare `except` catches all exceptions, masking errors


A bare except clause catches every exception, including system-exiting ones like KeyboardInterrupt or SystemExit. This can mask programming errors and make diagnosing problems difficult because no specific exceptions are handled explicitly.

Specify the exact exception type(s) to catch in the except clause or use multiple specific except blocks to handle different errors appropriately and maintain robust error handling.

Comment thread app/inventory.py
Comment on lines +97 to +99
except:
logger.warning("Failed to remove product: %s", sku)
return None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bare `except:` masks unexpected failures and control-flow errors


remove_product catches all exceptions, including non-recoverable ones, then silently downgrades them to None. That obscures root causes and can leave upstream logic believing removal simply failed.

Catch only KeyError for missing SKU and re-raise unexpected exceptions after logging.

Comment thread app/notifications.py
Comment on lines +86 to +88
query = "SELECT * FROM notifications WHERE recipient = '%s' AND read = 0" % recipient
try:
cursor = conn.execute(query)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

`%` string formatting enables SQL injection in `conn.execute`


get_unread builds query using % interpolation with user-controlled recipient. Attackers can inject SQL predicates to read notifications for unintended recipients and bypass logical access boundaries.

Replace string interpolation with a parameterized query using ? placeholders and pass recipient as a bound parameter to conn.execute

Comment thread app/notifications.py
Comment on lines +99 to +101
except:
logger.error("Failed to fetch notifications for %s", recipient)
return []

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

`except:` masks operational failures and hides real database errors


except: in get_unread suppresses all exception types and converts failures into normal-looking empty results. This obscures production outages and can break downstream logic that depends on distinguishing errors from true empty data.

Catch sqlite3.Error explicitly and re-raise unknown exceptions after logging details

Comment thread app/reporting.py
def generate_text_summary(
self,
data: list[dict[str, Any]],
columns: list[str] = [],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Mutable `columns=[]` default risks shared state bugs


columns is declared with a mutable default list. This creates latent cross-call state risk and brittle behavior once maintenance adds in-place list operations.

Use None as the default and allocate [] inside the method.

Comment thread app/reporting.py
Comment on lines +117 to +133
values = [
record[numeric_field]
for record in data
if numeric_field in record
and isinstance(record[numeric_field], (int, float))
]

if not values:
return {"count": 0}

return {
"count": len(values),
"total": sum(values),
"mean": sum(values) / len(values),
"min": min(values),
"max": max(values),
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unused `group_by` parameter returns incorrect ungrouped statistics


group_by is accepted but ignored, while output is always a single aggregate dictionary. This can mislead downstream decisions because grouped report expectations are silently violated.

Implement per-group aggregation when group_by is provided, or remove the parameter and update docs to match behavior.

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.

1 participant