Registry / web-framework / django-deprecation

django-deprecation

JSON →
library0.1.1pypypi✓ verified 23d ago

django-deprecation is a Python library designed to facilitate the deprecation and renaming of Django model fields without introducing breaking changes to existing code or requiring immediate, complex database migrations. It helps maintain backward compatibility during phased rollouts, especially in environments with rolling deployments. The current version is 0.1.1, and its release cadence appears to be feature-driven rather than time-based.

pip install django-deprecation
INSTALL
IMPORT
SIG · DJANGO-DEPRECATION
D
django-deprecation
web-frameworkpythonv0.1.1
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

DeprecatedField
from django_deprecation import DeprecatedField
from django_deprecation.fields import DeprecatedField

This example demonstrates how to use `DeprecatedField` to rename a model field (`musician` to `artist`) while maintaining backward compatibility for existing code that still references the old field name. The `DeprecatedField` ensures that lookups and access via the old name are correctly redirected to the new field. This typically involves a multi-step migration process.

import os import django from django.db import models from django_deprecation import DeprecatedField os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings') # Replace with your project settings django.setup() class Musician(models.Model): name = models.CharField(max_length=50) def __str__(self): return self.name class Album(models.Model): artist = models.ForeignKey(Musician, on_delete=models.CASCADE) # Deprecate 'musician' field, pointing to 'artist' musician = DeprecatedField('artist') name = models.CharField(max_length=100) def __str__(self): return self.name # Example usage (assuming models are migrated and data exists) # No runnable example for DB operations without full Django setup # print('Demonstrating DeprecatedField behavior:') # band = Musician.objects.create(name='The Beatles') # album = Album.objects.create(artist=band, name='Abbey Road') # assert album.musician == album.artist # print(f"Album name: {album.name}, Musician (deprecated): {album.musician.name}, Artist (new): {album.artist.name}")
Debug
Known issues
gotchaWhen deprecating and removing model fields, it is crucial to follow a multi-step deployment process, especially in rolling deployment environments. Failure to do so can lead to application crashes due to database schema mismatches. The recommended steps involve adding the `DeprecatedField`, deploying, running migrations, then later removing the deprecated field entirely and running migrations again.
fix
Implement a phased rollout: 1. Add `DeprecatedField` pointing to the new field, deploy, run `makemigrations` and `migrate`. 2. After all instances are updated, refactor code to use the new field. 3. Finally, remove the `DeprecatedField` entirely, deploy, run `makemigrations` and `migrate` again. This ensures database schema compatibility at each stage.
affects: All versions
gotchaThis `django-deprecation` library (by openbox) focuses on runtime aliasing and query handling for deprecated fields. Django also has built-in mechanisms like `system_check_deprecated_details` for raising developer warnings during system checks. These serve different purposes: `DeprecatedField` maintains runtime compatibility, while `system_check_deprecated_details` primarily informs developers of impending changes.
fix
Understand the distinct use cases. Use `django-deprecation.DeprecatedField` for seamless runtime field aliasing and query redirection. Use Django's `system_check_deprecated_details` on custom fields for static code analysis warnings to guide developers away from deprecated usage during development.
affects: All versions
gotchaBe aware of potential confusion with similarly named libraries like 'django-deprecate-fields' (by 3YOURMIND, version 0.2.3), which serves a similar purpose but might have different import paths or implementations. Ensure you are using the correct library based on your project's chosen dependency.
fix
Verify the `pypi-slug` and `source_url` for the library you intend to use. This entry specifically refers to `openbox/django-deprecation` (version 0.1.1) imported as `django_deprecation`. Check your `requirements.txt` and `setup.py` for clarity.
affects: All versions
Upgrade
Version history
0.1.1latest on PyPI · released Sep 7, 2018
Audit
Dependencies
DjangorequiredCore functionality; the library operates within Django's ORM and migration system.
Agent activity
15 hits · last 30 days
node
14
Resources
django-deprecation — pip install django-deprecation · libregistry