-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fixes #2073 -- Added DatabaseStore for persistent debug data storage. #2121
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
Merged
tim-schilling
merged 11 commits into
django-commons:serializable
from
dr-rompecabezas:2073-database-backed-store
May 14, 2025
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6b54dca
feat: add DatabaseStore for persistent debug data storage
dr-rompecabezas 17b27ce
refactor: rename DebugToolbarEntry to HistoryEntry and more
dr-rompecabezas a020331
Update 0001_initial.py
dr-rompecabezas 4e71a4a
Update models.py
dr-rompecabezas d37468f
Pin django-csp<4.0 in tox.ini
dr-rompecabezas 677a80a
Change _clean_up_old_entries to list
dr-rompecabezas 9d25201
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4aadebe
Refactor _cleanup_old_entries to eliminate code duplication
dr-rompecabezas fff3fae
Optimize entry creation logic to clean up old entries only when new e…
dr-rompecabezas d3329d1
Wrap creation and update methods in atomic transactions
dr-rompecabezas 2e69084
Avoid using .set() for database store
tim-schilling 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,24 @@ | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
initial = True | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="DebugToolbarEntry", | ||
fields=[ | ||
( | ||
"request_id", | ||
models.UUIDField(primary_key=True, serialize=False), | ||
), | ||
("data", models.JSONField(default=dict)), | ||
("created_at", models.DateTimeField(auto_now_add=True)), | ||
], | ||
options={ | ||
"verbose_name": "Debug Toolbar Entry", | ||
"verbose_name_plural": "Debug Toolbar Entries", | ||
"ordering": ["-created_at"], | ||
}, | ||
), | ||
] |
Empty file.
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,15 @@ | ||
from django.db import models | ||
|
||
|
||
class DebugToolbarEntry(models.Model): | ||
request_id = models.UUIDField(primary_key=True) | ||
data = models.JSONField(default=dict) | ||
created_at = models.DateTimeField(auto_now_add=True) | ||
|
||
class Meta: | ||
verbose_name = "Debug Toolbar Entry" | ||
verbose_name_plural = "Debug Toolbar Entries" | ||
dr-rompecabezas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ordering = ["-created_at"] | ||
|
||
def __str__(self): | ||
return str(self.request_id) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import uuid | ||
|
||
from django.test import TestCase | ||
|
||
from debug_toolbar.models import DebugToolbarEntry | ||
|
||
|
||
class DebugToolbarEntryTestCase(TestCase): | ||
def test_str_method(self): | ||
test_uuid = uuid.uuid4() | ||
entry = DebugToolbarEntry(request_id=test_uuid) | ||
self.assertEqual(str(entry), str(test_uuid)) | ||
|
||
def test_data_field_default(self): | ||
"""Test that the data field defaults to an empty dict""" | ||
entry = DebugToolbarEntry(request_id=uuid.uuid4()) | ||
self.assertEqual(entry.data, {}) | ||
|
||
def test_model_persistence(self): | ||
"""Test saving and retrieving a model instance""" | ||
test_uuid = uuid.uuid4() | ||
entry = DebugToolbarEntry(request_id=test_uuid, data={"test": True}) | ||
entry.save() | ||
|
||
# Retrieve from database and verify | ||
saved_entry = DebugToolbarEntry.objects.get(request_id=test_uuid) | ||
self.assertEqual(saved_entry.data, {"test": True}) | ||
self.assertEqual(str(saved_entry), str(test_uuid)) |
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
Oops, something went wrong.
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.