-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fixes: #19825 - Prevent cache for config revisions from being overwritten when in debug mode when not intended #20219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DanSheps
wants to merge
10
commits into
main
Choose a base branch
from
19825-fix-config-revision-revert-in-debug-mode
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
663f9a2
Fixes: #19825 - Prevent cache for config revisions from being overwri…
DanSheps 9854c66
Set ordering on the ConfigRevision to ensure consistency and usage of…
DanSheps 42857b1
Add active field on ConfigRevision model.
DanSheps dfff41b
Update migration and arrange for activation changes
DanSheps 0074199
Update migration and arrange for activation changes
DanSheps 98986fb
Merge remote-tracking branch 'origin/19825-fix-config-revision-revert…
DanSheps efa53e8
Merge branch 'main' of https://github.com/netbox-community/netbox int…
DanSheps 72845c9
Renumber mgiration
DanSheps 3fb8e8f
Correct error with activate
DanSheps 2b738f4
Revise config initialization, remove unneeded cache setting, update m…
DanSheps File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Generated by Django 5.2.5 on 2025-09-09 16:48 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
def get_active(apps, schema_editor): | ||
from django.core.cache import cache | ||
ConfigRevision = apps.get_model('core', 'ConfigRevision') | ||
version = None | ||
revision = None | ||
|
||
# Try and get the latest version from cache | ||
try: | ||
version = cache.get('config_version') | ||
except Exception: | ||
pass | ||
|
||
# If there is a version in cache, attempt to set revision to the current version from cache | ||
# If the version in cache does not exist or there is no version, try the lastest revision in the database | ||
if not version or (version and not (revision := ConfigRevision.objects.filter(pk=version).first())): | ||
revision = ConfigRevision.objects.order_by('-created').first() | ||
|
||
# If there is a revision set, set the active revision | ||
if revision: | ||
revision.active = True | ||
revision.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0018_concrete_objecttype'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='configrevision', | ||
name='active', | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.RunPython(code=get_active, reverse_code=migrations.RunPython.noop), | ||
migrations.AddConstraint( | ||
model_name='configrevision', | ||
constraint=models.UniqueConstraint( | ||
condition=models.Q(('active', True)), fields=('active',), name='unique_active_config_revision' | ||
), | ||
), | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.