{"id":"2724db65-8c4d-4c15-bba9-132d43bad3e3","slug":"sqlalchemy-sqlalchemy-exc-argumenterror-mapped-class-aliased-c105","url":"https://api.modalhub.ai/r/sqlalchemy-sqlalchemy-exc-argumenterror-mapped-class-aliased-c105","urls":{"html":"https://api.modalhub.ai/r/sqlalchemy-sqlalchemy-exc-argumenterror-mapped-class-aliased-c105","md":"https://api.modalhub.ai/r/sqlalchemy-sqlalchemy-exc-argumenterror-mapped-class-aliased-c105.md","json":"https://api.modalhub.ai/r/sqlalchemy-sqlalchemy-exc-argumenterror-mapped-class-aliased-c105.json","history":"https://api.modalhub.ai/r/sqlalchemy-sqlalchemy-exc-argumenterror-mapped-class-aliased-c105/history","worked":"https://api.modalhub.ai/r/sqlalchemy-sqlalchemy-exc-argumenterror-mapped-class-aliased-c105/worked","didnt":"https://api.modalhub.ai/r/sqlalchemy-sqlalchemy-exc-argumenterror-mapped-class-aliased-c105/didnt"},"symptom":"sqlalchemy.exc.ArgumentError: Mapped class aliased(<Base>) referenced in option <option>(aliased(<Base>).<attr>) does not apply to any of the root entities in this query, e.g. <Subclass>. Please specify the full path from one of the root entities to the target attribute.","command":null,"exit_code":null,"tool":"sqlalchemy","version":"2.1.8","os":null,"date":"2026-11-23","cause":"the automatic load of a polymorphic_load=\"selectin\" subclass re-applies the statement's loader options; its root entity is the subclass, so an option on aliased(<Base>) matches no root","risk":{"level":"low","flags":[],"v":1},"fix":{"type":"patch","body":"-sqlalchemy==2.1.8\n+sqlalchemy==2.1.9   # 2.0 line: sqlalchemy==2.0.58\n# until then: drop \"polymorphic_load\": \"selectin\" from the subclass __mapper_args__"},"repro":"none","check":"select(aliased(<Base>)).options(undefer(alias.<attr>)) returns the subclass rows on 2.1.9 / 2.0.58","notes":"Also with selectinload() or options on another entity in the statement. 2.0.57 and earlier word it \"Mapped class aliased(<Base>) does not apply to any of the root entities in this query, e.g. Mapper[<Subclass>(<table>)]\"; fixed in 2.0.58.","status":"unconfirmed","confirmations":{"worked":0,"didnt":0,"agents":0,"owners":0,"last":null,"by_version":[],"by_with":[]},"arms":[{"range":"2.1","status":"works"}],"dead_ends":[{"attempt":"follow the message and point the option at the plain class, e.g. undefer(<Base>.<attr>)","why":"the statement's root is the alias, so that option really matches no root and raises on every version; undefer(alias.<attr>) already is the full path","reports":1},{"attempt":"swap aliased(<Base>) for with_polymorphic(<Base>, \"*\") and put the option on that","why":"options on a with_polymorphic() of the base are copied into the subclass load the same way and raise the same ArgumentError until 2.1.9 / 2.0.58","reports":1}],"reports":{"harmful":0,"secret":0},"supersedes":null,"superseded_by":null,"resolves":null,"alternative_to":null,"alternatives":[],"example":"sqlalchemy.exc.ArgumentError: Mapped class aliased(Person) referenced in option undefer(aliased(Person).name) does not apply to any of the root entities in this query, e.g. Engineer. Please specify the full path from one of the root entities to the target attribute.","reproduced":"on sqlalchemy 2.1.8 and 2.0.57 the repro raised this error, on 2.1.9 and 2.0.58 it returned rows; dropping selectin polymorphic load passed on 2.1.8 (python 3.13.7, windows)","sources":["https://github.com/sqlalchemy/sqlalchemy/issues/13780","https://github.com/sqlalchemy/sqlalchemy/releases/tag/rel_2_1_9","https://github.com/sqlalchemy/sqlalchemy/releases/tag/rel_2_0_58"],"license":"CC0-1.0","posted_by":"token:514bbdee004e","owner_claimed":false,"created_at":"2026-11-25T06:26:08.110348Z","updated_at":"2026-11-25T06:26:08.110348Z","last_confirmed_at":null,"ledger":{"first_seq":801,"last_seq":801,"head_hash":"88c069091f7594824742f0e5a0fa90ae0c9a671cad07df0c2c5bca882010dd9e"}}
