Skip to content

Testing 5 mini - #95

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

Testing 5 mini#95
unnat-deepsource wants to merge 2 commits into
masterfrom
testing-5-mini

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 9:12a.m. Review ↗
Secrets Apr 20, 2026 9:12a.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.

@rupin-deepsource

Copy link
Copy Markdown

@deepsourcebot review

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.

`categories` argument is ignored, breaking caller expectations


get_low_stock accepts categories but never applies it. Callers relying on filtered low-stock alerts may act on incorrect results.

Implement category filtering logic using categories, or remove the parameter and update the docstring to match behavior.

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.

Bare `except` hides unexpected runtime failures


remove_product catches every exception, not just missing keys. Real defects in _products handling get swallowed, and callers receive None, obscuring operational failures.

Catch KeyError explicitly, and log unexpected exceptions with logger.exception before re-raising.

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` suppresses export data errors


export_snapshot catches all exceptions and continues. Corrupted product data can silently drop rows, producing incomplete exports and hidden data-quality defects.

Catch specific expected exceptions, and for unknown exceptions use logger.exception and fail fast or collect explicit error results.

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 `recipient` filter


get_unread builds query using % interpolation, then passes it to conn.execute. Attackers controlling recipient can alter WHERE logic and read other users’ notifications.

Replace string interpolation with a parameterized statement using ? placeholders and pass (recipient,) separately.

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:` swallows database errors and hides failure causes


A bare except: in get_unread suppresses root-cause visibility and masks runtime faults as normal empty results. This can silently break alert delivery logic and delay incident diagnosis.

Catch sqlite3.Error explicitly, log the exception details, and re-raise or return a typed error path distinct from valid empty results.

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


Using filters: dict[str, Any] = {} creates one shared dictionary for every invocation. If later code mutates it, callers can influence each other and produce hard-to-reproduce failures.

Replace with filters: Optional[dict[str, Any]] = None and initialize filters = {} inside the method

Comment thread app/reporting.py
Comment on lines +56 to +61
fieldnames = list(data[0].keys())
writer = csv.DictWriter(output, fieldnames=fieldnames)
writer.writeheader()

for record in data:
writer.writerow(record)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

`csv.DictWriter` raises on rows with extra keys


Using first-row keys as a fixed schema can crash exports when later rows have additional fields. One malformed or richer record stops the entire report and loses output.

Build fieldnames as the union of keys across all records, or configure extrasaction='ignore' to tolerate extra keys

Comment thread app/reporting.py
Comment on lines +60 to +61
for record in data:
writer.writerow(record)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unsanitized `writer.writerow` allows spreadsheet formula execution


writer.writerow(record) emits untrusted cell values directly into CSV output. If user-controlled text starts with formula prefixes, spreadsheet clients can execute payloads, enabling data exfiltration or command invocation via client integrations.

Sanitize each string cell before writing by prefixing dangerous leading characters with a quote or tab

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 returns incorrect aggregate scope


The implementation ignores group_by, so grouped summaries are never produced despite API and docstring promises. Consumers can trust incorrect results and make wrong inventory decisions.

Implement grouping logic when group_by is provided, returning stats keyed by group value; otherwise keep current global aggregate 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