Skip to content

Test 5 mini fp - #92

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

Test 5 mini fp#92
unnat-deepsource wants to merge 2 commits into
masterfrom
test-5.1-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 7:58a.m. Review ↗
Secrets Apr 20, 2026 7:58a.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 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
"""Remove a product from inventory."""
try:
return self._products.pop(sku)
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/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.

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/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/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 +65 to +75
def get_low_stock(self, categories: list[str] = []) -> list[Product]:
"""Return products below the low stock threshold.

Args:
categories: Optional filter by category names.
"""
low = [
p for p in self._products.values()
if p.quantity < self.LOW_STOCK_THRESHOLD
]
return low

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

`categories` argument ignored causing incorrect low-stock filtering


get_low_stock accepts categories but returns all low-stock products regardless. This creates silent logic errors in alerting workflows and contradicts the method contract.

Either implement category-aware filtering or remove the parameter and update the docstring to match real behavior.

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.

`except:` hides export errors and loses data


The broad catch in export_snapshot turns unexpected errors into logs and returns partial results. Downstream consumers may trust incomplete inventory snapshots and make incorrect operational decisions.

Catch specific expected exceptions only, and raise or return an explicit failure status for unexpected exceptions.

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-formatted `query` enables SQL injection


get_unread builds SQL using % formatting, so malicious recipient values can inject clauses like OR 1=1. That can bypass recipient filtering and expose notifications across accounts.

Replace with a parameterized statement and bound arguments: ... WHERE recipient = ? AND read = 0, then pass (recipient,) 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.

Bare `except:` hides database and programming failures


The bare handler swallows unexpected exceptions and returns [], masking operational failures and making incidents hard to detect. It can silently drop notification visibility for users.

Catch sqlite3.Error explicitly and log exception details with logger.exception; re-raise non-database exceptions so defects fail fast

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` silently drops requested grouped statistics


generate_summary_stats accepts group_by but never uses it. Consumers expecting per-group metrics receive ungrouped totals, which can mislead business decisions and tests may miss semantic mismatch.

Implement grouping logic keyed by group_by, or remove the parameter and update docstring/type contract to avoid false expectations

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