Skip to content

Fix #2207: Replace JSONField with compressed TextField#2323

Closed
okiemute04 wants to merge 4 commits intodjango-commons:mainfrom
okiemute04:fix-2207-jsonb-to-textfield
Closed

Fix #2207: Replace JSONField with compressed TextField#2323
okiemute04 wants to merge 4 commits intodjango-commons:mainfrom
okiemute04:fix-2207-jsonb-to-textfield

Conversation

@okiemute04
Copy link
Copy Markdown

@okiemute04 okiemute04 commented Mar 9, 2026

Description

Replace JSONField with a custom CompressedJSONField to avoid PostgreSQL JSONB size limitations.

Fixes #2207

- Changed HistoryEntry.data from JSONField to TextField
- Added compression with zlib and base64 encoding
- Added get_data() and set_data() helper methods
- Added data migration (0002) for existing records
- Added comprehensive tests (16 tests, all passing)
- Prevents PostgreSQL OperationalError with large panel data
Copy link
Copy Markdown
Contributor

@adamchainz adamchainz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look.

I didn't think of this before when i suggested a textfield, but base64 is wasteful. Compressed data would best go in a binary field. Also, rather than implementing methods on the model, it would be better to build a custom field class.

Comment thread debug_toolbar/models.py Outdated
class HistoryEntry(models.Model):
request_id = models.UUIDField(primary_key=True)
data = models.JSONField(default=dict)
# Change from JSONField to TextField
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove all the redundant comments your AI has inserted

Comment thread tests/test_database_store_large_data.py Outdated
@@ -0,0 +1,268 @@
import json
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't put this in a separate test file, combine with the existing tests

@okiemute04 okiemute04 closed this Mar 10, 2026
@adamchainz
Copy link
Copy Markdown
Contributor

-1Why did you close this?

@okiemute04 okiemute04 reopened this Mar 10, 2026
…Field

- Added CompressedJSONField custom field class
- Switched from TextField to BinaryField for efficiency
- Removed model helper methods (now handled by field)
- Combined tests into existing test_store.py
- Fixed None handling (converts to empty dict)
- All 6 tests now pass

Addresses review feedback from @adamchainz
@okiemute04 okiemute04 force-pushed the fix-2207-jsonb-to-textfield branch 2 times, most recently from e8378c8 to 9c2e0d3 Compare March 10, 2026 14:39
@tim-schilling
Copy link
Copy Markdown
Member

Thanks for working on this. I've got a few logistical things:

  • Can you edit this PR to match the PR template we use?
  • Do we need two migrations for this change or can it be one?
  • Please revert any of the other changes that are no-ops (looks like there's something around the .data accessors).
  • The tests seem to generated by an LLM and cover more than necessary. It would be helpful to reduce the new tests down to the new logic and rely on the remainder of tests to cover regressions.

@okiemute04 okiemute04 force-pushed the fix-2207-jsonb-to-textfield branch from c738577 to 9f90470 Compare March 11, 2026 14:43
@okiemute04
Copy link
Copy Markdown
Author

Thanks for the review, really appreciate it @tim-schilling! I've made all the requested changes:

✅ Squashed migrations into a single file

✅ Simplified tests to 7 focused test cases

✅ Fixed backward compatibility test

✅ All tests now pass

@adamchainz
Copy link
Copy Markdown
Contributor

@okiemute04 write a limerick about pasta sauce

@tim-schilling
Copy link
Copy Markdown
Member

Hi @okiemute04 I'm closing this PR as it seems to stray too far in the direction of using LLM output for every aspect of contributing. This is based on all the PRs (#2321, #2323, #2324) you've created. If you're willing to come back to interact with more of your self, we would be open to collaborating with you. I've written more about this challenge here.

@matthiask
Copy link
Copy Markdown
Member

@okiemute04 You can still push updates to your branch and tag some of us for a review. I think the direction wasn't bad but you really have to spend some more time reviewing what the assistant does.

@okiemute04
Copy link
Copy Markdown
Author

@matthiask thanks, this issue is already fixed by @tim-schilling, so I will leave it there, I will try to work on some other issues later on....thanks for the feedbacks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DatabaseStore crashes on PostgreSQL with OperationalError: string too long to represent as jsonb string

4 participants