fix: Fix AttributeError in report_categories

- Add .label('category') to SQLAlchemy query for proper Row attribute access
- Change filter_by to filter() for better NULL handling

Fixes 500 error on /raporty/struktura-branzowa

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Maciej Pienczyn 2026-01-14 08:29:00 +01:00
parent 2f37267475
commit 14e969bc6d

6
app.py
View File

@ -8740,7 +8740,7 @@ def report_categories():
try:
# Grupowanie po kategoriach
category_counts = db.query(
Company.category,
Company.category.label('category'),
func.count(Company.id).label('count')
).group_by(Company.category).all()
@ -8749,8 +8749,8 @@ def report_categories():
categories = []
for cat in category_counts:
cat_name = cat.category or 'Brak kategorii'
examples = db.query(Company.name).filter_by(
category=cat.category
examples = db.query(Company.name).filter(
Company.category == cat.category
).limit(3).all()
categories.append({