Deprecate old tenant model imports
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.pyre-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, ProgramManagerfrom 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:
- Add deprecation warnings to
tenants/models.py
- Import Python's
warningsmodule - Add a deprecation warning when the module is imported
- Include clear migration instructions in the warning message
- 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)
- Import mapping guide:
Tenant, ProgramManager→tenants.models.baseApplicationWebhooks→tenants.models.webhooksProgramSub→tenants.models.subscriptionsProgramZone, ProgramAssignedZoningBuilding, ProgramAssignedZoningBuildingType→tenants.models.zonesProgramAssignedBuilding, ProgramBuildingBundle→tenants.models.buildingsProgramMapLayer, ProgramGeoJSONMapLayer, ProgramGeoJSONProgramAreaLayer→tenants.models.gis_layers
- Update documentation
- Add migration notes to CONTRIBUTING.md
- Update any import examples in docstrings
- 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.pytenants/management/commands/sync_gis_connections.pytenants/management/commands/sync_program_area_layer.pytenants/management/commands/sync_zoning_layer.pytenants/management/commands/sync_parcel_layer.pytenants/management/commands/assign_zone_categories.pytenants/management/commands/destroy_tenant.pytenants/management/commands/analyze_zone_matching.py
Tests:
tests/tenants/test_sync_tenant_info.pytests/tenants/test_sync_gis_connections.pytests/tenants/test_sync_program_area.pytests/tenants/test_single_tenant_middleware.pytests/tenants/test_single_tenant_endpoint.pytests/tenants/test_parcel_search_usps_integration.pytests/tenants/test_models.pytests/tenants/test_destroy_tenant.pytests/tenants/test_admin.pytests/tenants/test_arcgis_data.pytests/helpers.pytests/custom_user/test_registration.pytests/pz_utils/test_airtable_dtos.py
Views/Serializers/Utils:
pz_utils/airtable_integration/views.pypz_utils/airtable_integration/serializers.pypz_utils/airtable_integration/airtable.pypz_utils/airtable_integration/airtableDTOs.pyonline_orders/views.pycustom_user/views.pybuildings/views.pytenants/utils/tenant/helpers.py
Models/Admin:
online_orders/models.pybuildings/models.pysubscriptions/admin.py
Services:
pz_utils/management/services.pytenants/services/gis_service.py
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗