MCPcopy
hub / github.com/django/django / _nodb_cursor

Method _nodb_cursor

django/db/backends/postgresql/base.py:517–552  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

515
516 @contextmanager
517 def _nodb_cursor(self):
518 cursor = None
519 try:
520 with super()._nodb_cursor() as cursor:
521 yield cursor
522 except (Database.DatabaseError, WrappedDatabaseError):
523 if cursor is not None:
524 raise
525 warnings.warn(
526 "Normally Django will use a connection to the 'postgres' database "
527 "to avoid running initialization queries against the production "
528 "database when it's not needed (for example, when running tests). "
529 "Django was unable to create a connection to the 'postgres' database "
530 "and will use the first PostgreSQL database instead.",
531 RuntimeWarning,
532 )
533 for connection in connections.all():
534 if (
535 connection.vendor == "postgresql"
536 and connection.settings_dict["NAME"] != "postgres"
537 ):
538 conn = self.__class__(
539 {
540 **self.settings_dict,
541 "NAME": connection.settings_dict["NAME"],
542 },
543 alias=self.alias,
544 )
545 try:
546 with conn.cursor() as cursor:
547 yield cursor
548 finally:
549 conn.close()
550 break
551 else:
552 raise
553
554 @cached_property
555 def pg_version(self):

Callers 1

_clone_test_dbMethod · 0.45

Calls 3

cursorMethod · 0.80
allMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected