Deprecate old tenant model imports

Resolved 💬 2 comments Opened Jun 8, 2025 by matthew-petty Closed Jun 8, 2025

Problem Description

The tenant models have been refactored into a modular structure with separate files for different model categories (base, webhooks, subscriptions, zones, buildings, gis_layers). While backward compatibility is maintained through the old tenants.models module, we need to deprecate the old import patterns and migrate all code to use the new modular imports.

Current State

  • Old import pattern: from tenants.models import Tenant, ProgramZone, etc.
  • 34 files currently use the old import pattern
  • The old tenants/models.py re-exports all models for backward compatibility
  • Only 2 files currently use the new modular import structure

Desired State

  • All imports should use the new modular structure:
  • from tenants.models.base import Tenant, ProgramManager
  • from tenants.models.zones import ProgramZone, ProgramAssignedZoningBuilding
  • etc.
  • Deprecation warnings added to old import paths
  • All code migrated to new import patterns
  • Old import module can eventually be removed

Recommended Approach

We will use Manual Migration to update all imports:

  1. Add deprecation warnings to tenants/models.py
  • Import Python's warnings module
  • Add a deprecation warning when the module is imported
  • Include clear migration instructions in the warning message
  1. Update imports by category (34 files total):
  • Management commands (11 files)
  • Tests (12 files)
  • Views and serializers (7 files)
  • Models and admin files (4 files)
  1. Import mapping guide:
  • Tenant, ProgramManagertenants.models.base
  • ApplicationWebhookstenants.models.webhooks
  • ProgramSubtenants.models.subscriptions
  • ProgramZone, ProgramAssignedZoningBuilding, ProgramAssignedZoningBuildingTypetenants.models.zones
  • ProgramAssignedBuilding, ProgramBuildingBundletenants.models.buildings
  • ProgramMapLayer, ProgramGeoJSONMapLayer, ProgramGeoJSONProgramAreaLayertenants.models.gis_layers
  1. Update documentation
  • Add migration notes to CONTRIBUTING.md
  • Update any import examples in docstrings
  1. Run comprehensive tests
  • Ensure all tests pass after migration
  • Verify deprecation warnings are displayed

Success Criteria

  • [ ] All 34 files updated to use new import patterns
  • [ ] Deprecation warnings implemented in tenants/models.py
  • [ ] All tests pass with new imports
  • [ ] No runtime errors from import changes
  • [ ] Documentation updated with migration guide
  • [ ] CI/CD pipeline validates new import patterns

Additional Context

This refactoring is part of a larger effort to improve code organization and maintainability. The modular structure makes it easier to understand model relationships and reduces the risk of circular imports. Manual migration was chosen to allow for careful review and potential refactoring of imports during the update process.

Files to Update

Management Commands:

  • tenants/management/commands/sync_tenant_info.py
  • tenants/management/commands/sync_gis_connections.py
  • tenants/management/commands/sync_program_area_layer.py
  • tenants/management/commands/sync_zoning_layer.py
  • tenants/management/commands/sync_parcel_layer.py
  • tenants/management/commands/assign_zone_categories.py
  • tenants/management/commands/destroy_tenant.py
  • tenants/management/commands/analyze_zone_matching.py

Tests:

  • tests/tenants/test_sync_tenant_info.py
  • tests/tenants/test_sync_gis_connections.py
  • tests/tenants/test_sync_program_area.py
  • tests/tenants/test_single_tenant_middleware.py
  • tests/tenants/test_single_tenant_endpoint.py
  • tests/tenants/test_parcel_search_usps_integration.py
  • tests/tenants/test_models.py
  • tests/tenants/test_destroy_tenant.py
  • tests/tenants/test_admin.py
  • tests/tenants/test_arcgis_data.py
  • tests/helpers.py
  • tests/custom_user/test_registration.py
  • tests/pz_utils/test_airtable_dtos.py

Views/Serializers/Utils:

  • pz_utils/airtable_integration/views.py
  • pz_utils/airtable_integration/serializers.py
  • pz_utils/airtable_integration/airtable.py
  • pz_utils/airtable_integration/airtableDTOs.py
  • online_orders/views.py
  • custom_user/views.py
  • buildings/views.py
  • tenants/utils/tenant/helpers.py

Models/Admin:

  • online_orders/models.py
  • buildings/models.py
  • subscriptions/admin.py

Services:

  • pz_utils/management/services.py
  • tenants/services/gis_service.py

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗