(self)
| 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): |
no test coverage detected