| 4 | |
| 5 | |
| 6 | def check_site_id(app_configs, **kwargs): |
| 7 | # Inner import avoids AppRegistryNotReady |
| 8 | from django.contrib.sites.models import Site |
| 9 | |
| 10 | if hasattr(settings, "SITE_ID"): |
| 11 | try: |
| 12 | site_id = Site._meta.pk.to_python(settings.SITE_ID) |
| 13 | except ValidationError as exc: |
| 14 | return [ |
| 15 | Error( |
| 16 | f"The SITE_ID setting failed to validate: {exc}.", id="sites.E101" |
| 17 | ), |
| 18 | ] |
| 19 | else: |
| 20 | # to_python() might coerce a SITE_ID of the wrong type to the valid |
| 21 | # type, e.g. "1" to 1 for AutoField. |
| 22 | if site_id != settings.SITE_ID: |
| 23 | expected_type = type(site_id).__name__ |
| 24 | return [ |
| 25 | Error( |
| 26 | f"The SITE_ID setting must be of type {expected_type}.", |
| 27 | id="sites.E101", |
| 28 | ), |
| 29 | ] |
| 30 | return [] |