From 73a9a744d55966096feb1535c94fbad1925d0d91 Mon Sep 17 00:00:00 2001 From: Markus Graf Date: Thu, 16 Oct 2025 15:37:13 +0200 Subject: [PATCH] Fix AttributeError: can't set attribute 'is_active' in User model MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Flask-Login's UserMixin provides is_active as a read-only property. Attempting to set it as an instance attribute caused a conflict. Solution: - Store active status in private attribute _is_active - Override is_active property to return custom value - Update to_dict() to use _is_active This allows proper Flask-Login integration while maintaining custom active status tracking. Bug found during login testing: AttributeError when calling User.get_by_username() which triggered from_dict() → __init__(). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/models/user.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/models/user.py b/app/models/user.py index 4796811..5c5fc8d 100644 --- a/app/models/user.py +++ b/app/models/user.py @@ -25,12 +25,17 @@ class User(UserMixin): self.password_hash = password_hash self.role = role self.product_ids = product_ids or [] - self.is_active = is_active + self._is_active = is_active def get_id(self): """Get user ID for Flask-Login""" return self.user_id + @property + def is_active(self): + """Check if user account is active (Flask-Login property)""" + return self._is_active + @property def is_authenticated(self): """Check if user is authenticated""" @@ -78,7 +83,7 @@ class User(UserMixin): 'password_hash': self.password_hash, 'role': self.role, 'product_ids': self.product_ids, - 'is_active': self.is_active + 'is_active': self._is_active } @classmethod