diff --git a/__init__.py b/__init__.py index 44f4eb3..5e4fc23 100644 --- a/__init__.py +++ b/__init__.py @@ -1,3 +1,5 @@ +import warnings + from CTFd.models import Flags, Users, db from CTFd.plugins import ( register_admin_plugin_menu_bar, @@ -8,6 +10,7 @@ from CTFd.plugins.migrations import upgrade from CTFd.utils.config import is_teams_mode from CTFd.utils.decorators import admins_only from flask import Blueprint, redirect, render_template, request, url_for +from sqlalchemy.exc import SAWarning from sqlalchemy.orm import joinedload from .flags import PersonalFlag @@ -41,7 +44,16 @@ def create_flag_if_missing(challenge_id: int, user_id: int, flag_content: str) - data=data, ) db.session.add(flag) - db.session.commit() + # CTFd's Flags model sets polymorphic_on without mapping any type, so + # SQLAlchemy warns on every flag flush (static flags too). Mapping + # "personal" would break loading the other types: ignore it here. + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", + message="Flushing object .* with incompatible polymorphic identity", + category=SAWarning, + ) + db.session.commit() return flag.id