Zettelkasten

django connection_created signal은 django.backends.mysql.DatabaseWrapper가 초기화 될 때 호출된다.

·수정 2026.04.23·수정 1

요약

  • django.backends.mysql.DatabaseWrapper가 초기화 될때 호출된다.

본문

  • pymysql.install_as_MySQLdb는 MySQLdb를 patching함
    • django에서 MySQLdb 사용하는 부분 찾기
  • django.db.backends.mysql.base.DatabaseWrapper.get_new_connection에서 Database.connect로 호출
  • django.backends.base.base.BaseDatabaseWrapper.connect에서 connection_created 호출
  • django.db.backends.mysql.base.DatabaseWrapperdjango.backends.base.base.BaseDatabaseWrapper을 상속하고 있음
  • 즉 DatabaseWrapper 초기화 시점에 connection_created가 호출됨
  • DatabaseWrapper는 django.db.utils.ConnectionHandler.create_connection 초기화됨
  • django.db.__init__.py에서 connections = ConnectionHandler()
    • connections는 ConnectionProxy로 감싸짐
    • connection = ConnectionProxy(connections, DEFAULT_DB_ALIAS)
  • django.db.connections.create_connection 호출시
  • connections["default" ] 호출 시
  • 참고용
    • init_command는 pymsql.connections.Connnection.connect 에서 호출됨

이 문서를 참조하는 노트 (1)