CodeVetter · Repo Unpack · Behavior traces
sqlalchemy/sqlalchemy
Four concrete flows were followed through source: engine creation and first connection, Core statement execution, ORM persistence and commit, and async connection execution. The traces preserve important branches such as plugin intervention, insertmanyvalues, dependency cycles, and failed flush rollback. A fifth trace connects ORM query execution to identity-map materialization. These describe source behavior, not observed runtime outcomes.
- Startup: create_engine → make_url → URL._instantiate_plugins → URL._get_entrypoint → get_dialect_cls/get_async_dialect_cls → import_dbapi → dialect construction → pool construction → Engine construction → engine_created hooks.
- First connection: Engine.connect → Connection.__init__ → Engine.raw_connection → Pool.connect → _ConnectionFairy._checkout; creating a fresh record invokes the creator, and the registered connect handler initializes the dialect and rolls back initialization work.
- Core action: Connection.execute → _distill_params_20 → ClauseElement._execute_on_connection → Connection._execute_clauseelement → _compile_w_cache → _execute_context; non-executable input raises ObjectNotExecutableError.
- Driver execution: _execute_context → transaction validation/autobegin → pre_exec → _exec_insertmany_context or _exec_single_context; ordinary execution chooses do_executemany, do_execute_no_params, or do_execute, then post_exec → _setup_result_proxy.
- Persistence: Session.add → instance_state → _save_or_update_state; Session.flush → _flush → UOWTransaction registration → execute → _generate_actions → topological ordering, with dependency cycles converted to per-state actions.
- Commit: Session.commit → SessionTransaction.commit → _prepare_impl → repeated flush until clean, capped at 100 → participating transaction commits → after_commit → snapshot removal → close; _SaveUpdateAll reaches persistence._save_obj during flush.
- ORM read: Session._execute_internal → ORM preparation and autoflush → get_bind → _connection_for_bind → orm_execute_statement → conn.execute → orm_setup_cursor_result → loading.instances → identity-map lookup or new_instance.
- Async action: AsyncEngine.connect creates an AsyncConnection; entering or awaiting it calls start → greenlet_spawn(sync_engine.connect). execute calls greenlet_spawn(_proxied.execute, _require_await=True) → _ensure_sync_result, and the bridge raises AwaitRequired if no driver await occurs.