Skip to content

Test 5 mini fp - #94

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

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

Conversation

@unnat-deepsource

Copy link
Copy Markdown
Collaborator

No description provided.

@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:46a.m. Review ↗
Secrets Apr 20, 2026 8:46a.m. Review ↗

Comment thread app/notifications.py
def get_unread(self, recipient: str) -> list[dict]:
"""Fetch unread notifications for a recipient."""
conn = self._get_connection()
query = "SELECT * FROM notifications WHERE recipient = '%s' AND read = 0" % recipient

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Possible SQL injection vector through string-based query construction.


Constructing SQL query using user provided data is insecure. It makes application vulnerable to [SQL injection](SQL injection) attacks.

Comment thread app/notifications.py
def get_unread(self, recipient: str) -> list[dict]:
"""Fetch unread notifications for a recipient."""
conn = self._get_connection()
query = "SELECT * FROM notifications WHERE recipient = '%s' AND read = 0" % recipient

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Formatting a regular string which could be a f-string


f-strings are the fastest way to format strings as compared to the following methods: * using format specifiers %

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 imported from dataclasses


An object has been imported but is not used anywhere in the file.
It should either be used or the import should be removed.

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.

Dangerous default value [] as argument


Do not use a mutable like list or dictionary as a default value to an argument. Python’s default arguments are evaluated once when the function is defined. Using a mutable default argument and mutating it will mutate that object for all future calls to the function as well.

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.

Dangerous default value {} as argument


Do not use a mutable like list or dictionary as a default value to an argument. Python’s default arguments are evaluated once when the function is defined. Using a mutable default argument and mutating it will mutate that object for all future calls to the function as well.

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.

do not use bare 'except'


Using except without a specific exception can be error prone.

Comment thread app/notifications.py
}
for row in cursor.fetchall()
]
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.

do not use bare 'except'


Using except without a specific exception can be error prone.

Comment thread app/reporting.py
def generate_csv(
self,
data: list[dict[str, Any]],
filters: dict[str, Any] = {},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Dangerous default value {} as argument


Do not use a mutable like list or dictionary as a default value to an argument. Python’s default arguments are evaluated once when the function is defined. Using a mutable default argument and mutating it will mutate that object for all future calls to the function as well.

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.

Dangerous default value [] as argument


Do not use a mutable like list or dictionary as a default value to an argument. Python’s default arguments are evaluated once when the function is defined. Using a mutable default argument and mutating it will mutate that object for all future calls to the function as well.

Comment thread app/reporting.py
lines.append(f"Total: {len(data)} records")
return "\n".join(lines)

def generate_summary_stats(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Method doesn't use the class instance and could be converted into a static method


The method doesn't use its bound instance. Decorate this method with @staticmethod decorator, so that Python does not have to instantiate a bound method for every instance of this class thereby saving memory and computation. Read more about staticmethods here.

@unnat-deepsource

Copy link
Copy Markdown
Collaborator Author

@deepsourcebot review

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 non-recoverable runtime failures


A bare except catches KeyboardInterrupt and SystemExit alongside expected lookup errors. This hides real defects and can keep the process running in corrupted states while callers only see None.

Catch KeyError explicitly and log unexpected exceptions separately with except Exception before re-raising.

Comment thread app/inventory.py
Comment on lines +127 to +128
except:
logger.error("Failed to export product %s", product.sku)

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` hides export data corruption causes


Catching every exception makes export reliability opaque and can silently lose inventory records. Operators only get a generic log message, while the root error and stack context are discarded.

Use except Exception as exc with logger.exception(...), and consider re-raising or collecting failed SKUs for explicit caller handling.

Comment thread app/notifications.py
def get_unread(self, recipient: str) -> list[dict]:
"""Fetch unread notifications for a recipient."""
conn = self._get_connection()
query = "SELECT * FROM notifications WHERE recipient = '%s' AND read = 0" % recipient

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

`%` SQL formatting enables `recipient` query injection


get_unread constructs query with % interpolation of untrusted recipient. Attackers can alter the WHERE clause and read notifications not belonging to them.

Replace string formatting with parameterized SQL using ? placeholders and pass (recipient,) to 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:` hides runtime failures and returns stale behavior


get_unread swallows every exception and returns [], making real database or schema failures look like no unread notifications. This can suppress alerts and mislead downstream logic.

Replace except: with except sqlite3.Error as exc, log exc, and re-raise or return a typed error outcome

Comment thread app/reporting.py
def generate_csv(
self,
data: list[dict[str, Any]],
filters: dict[str, Any] = {},

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 `filters={}` default risks shared state bugs


filters uses a mutable default object. Even though current code does not mutate it, later edits can accidentally persist values across calls and create hard-to-debug cross-request coupling.

Replace with None and initialize inside the method using filters = {} if filters is None else filters.

Comment thread app/reporting.py
self,
data: list[dict[str, Any]],
numeric_field: str,
group_by: Optional[str] = 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.

Unused `group_by` parameter breaks advertised grouped statistics


The API accepts group_by but never applies grouping. Callers expecting per-group metrics silently receive global numbers, which can corrupt dashboards and downstream decisions.

Implement grouping when group_by is provided, or remove the parameter and update docstrings to match actual behavior.

@rupin-deepsource

Copy link
Copy Markdown

@deepsourcebot review

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