Skip to content

Comments

Remove obsolete JSON format support from Live Data Server#57

Merged
darshdinger merged 7 commits intonextfrom
ewm14160_remove_obsolete_option
Jan 8, 2026
Merged

Remove obsolete JSON format support from Live Data Server#57
darshdinger merged 7 commits intonextfrom
ewm14160_remove_obsolete_option

Conversation

@darshdinger
Copy link
Contributor

Short description of the changes:

Removed the obsolete JSON data format option for publishing plot data. The server now only accepts HTML format data. The data_type field remains in the database model for backward compatibility but is effectively always set to 1 (HTML).

Long description of the changes:

This PR addresses issues with the fragile JSON format detection logic (the <div string check in get_data_type_from_data() method) that caused problems with REF_M data processing.

Changes made:

  • Simplified DATA_TYPES constant from {"json": 0, "html": 1} to {"html": 1}
  • Removed JSON upload endpoint (/update/json/)
  • Removed user data endpoints (/upload_user_data/ and /list/)
  • Removed get_data_type_from_data() and get_data_type_from_string() helper methods
  • Simplified _store() function to always use HTML data type
  • Removed store_user_data() from view utilities
  • Updated tests to remove JSON and user data test cases
  • Cleaned up documentation references to JSON format

The database schema remains unchanged - the data_type field is preserved to avoid migration complexity and maintain backward compatibility with existing data.

Check list for the pull request

  • I have read the [CONTRIBUTING]
  • I have read the [CODE_OF_CONDUCT]
  • I have added tests for my changes
  • I have updated the documentation accordingly

Check list for the reviewer

  • I have read the [CONTRIBUTING]
  • I have verified the proposed changes
  • best software practices
    • all internal functions have an underbar, as is python standard
    • clearly named variables (better to be verbose in variable names)
    • code comments explaining the intent of code blocks
  • All the tests are passing
  • The documentation is up to date
  • code comments added when explaining intent

Manual test for the reviewer

  1. Start the Docker environment: docker compose up -d
  2. Verify the Django container starts successfully
  3. Run the test suite in the pixi environment: pixi shell then pytest
  4. All 9 tests should pass (2 enum tests, 2 expiration tests, 5 post/get tests)
  5. Test uploading HTML plot data:
    curl -X POST http://localhost/plots/TEST_INST/12345/upload_plot_data/ \
      -F "file=@tests/data/reflectivity.html" \
      -F "data_id=test_plot" \
      -H "Authorization: <test_key>"
  6. Verify the old JSON endpoint returns 404:
    curl http://localhost/plots/TEST_INST/12345/update/json/

References

  • Related to REF_M data processing issues caused by fragile <div string detection
  • EWM Work Item: EWM # 14160

@codecov
Copy link

codecov bot commented Dec 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.51%. Comparing base (efdf308) to head (c02fb92).
⚠️ Report is 10 commits behind head on next.

Additional details and impacted files
@@            Coverage Diff             @@
##             next      #57      +/-   ##
==========================================
- Coverage   89.97%   85.51%   -4.46%     
==========================================
  Files          12       12              
  Lines         359      283      -76     
==========================================
- Hits          323      242      -81     
- Misses         36       41       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@backmari
Copy link
Collaborator

backmari commented Jan 8, 2026

@coderabbitai full review

@coderabbitai
Copy link

coderabbitai bot commented Jan 8, 2026

✅ Actions performed

Full review triggered.

@coderabbitai
Copy link

coderabbitai bot commented Jan 8, 2026

📝 Walkthrough

Walkthrough

The changes implement a simplification of the plot data management system by removing support for multiple data types and associated features. The system now exclusively supports HTML data storage, eliminating JSON handling and user-data upload workflows. This involves updating the data type constants and removing related model methods, removing URL patterns for JSON and user endpoints, simplifying view functions to eliminate JSON retrieval paths, reducing utility functions to focus on HTML-based operations, and streamlining tests to verify only the remaining HTML-based functionality.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 76.47% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: removing JSON format support from the Live Data Server.
Description check ✅ Passed The description provides a clear explanation of the changes made and relates directly to the changeset, covering the removal of JSON support and related endpoints.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ewm14160_remove_obsolete_option

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
src/apps/plots/models.py (1)

59-70: Update stale documentation referencing JSON.

The docstring on line 60 and comments on lines 64-66 and 69 still reference JSON data type support, which has been removed. Consider updating these to reflect the HTML-only design.

📝 Suggested documentation update
 class PlotData(models.Model):
-    """Table of plot data. This data can either be json or html"""
+    """Table of plot data. This data is stored as HTML."""

     ## DataRun this run status belongs to
     data_run = models.ForeignKey(DataRun, on_delete=models.deletion.CASCADE)
-    ## Data type:
-    ##    type = 100 for live data, 0 static reduced.
-    ##    type += 1 for HTML, 0 for JSON
+    ## Data type: 1 for HTML (JSON support removed)
+    ## Legacy: type = 100 for live data, 0 for static reduced
     data_type = models.IntegerField()

-    ## JSON/HTML data
+    ## HTML data
     data = models.TextField()
tests/test_expiration.py (2)

116-127: Extract duplicate _generate_key to a shared test utility.

This function is duplicated verbatim in tests/test_post_get.py (lines 142-153). Consider extracting it to a shared test utilities module (e.g., tests/conftest.py or tests/utils.py) to maintain DRY principles.


73-83: Consider adding timeout to test HTTP requests.

The requests.get calls lack timeout parameters, which could cause tests to hang indefinitely if the server is unresponsive. This is flagged by static analysis (S113).

🔧 Add timeout to requests
         response1 = requests.get(
             f"{TEST_URL}/plots/{instrument}/12345/update/html/",
             headers={"Authorization": _generate_key(instrument, 12345)},
+            timeout=30,
         )
         assert response1.status_code == HTTP_OK

         response2 = requests.get(
             f"{TEST_URL}/plots/{instrument}/12346/update/html/",
             headers={"Authorization": _generate_key(instrument, 12346)},
+            timeout=30,
         )
         assert response2.status_code == HTTP_OK
tests/test_post_get.py (1)

142-153: Duplicate helper function.

As noted in tests/test_expiration.py, this _generate_key function is duplicated. Consider consolidating into a shared test utility.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between efdf308 and ba8edb0.

📒 Files selected for processing (6)
  • src/apps/plots/models.py
  • src/apps/plots/urls.py
  • src/apps/plots/view_util.py
  • src/apps/plots/views.py
  • tests/test_expiration.py
  • tests/test_post_get.py
💤 Files with no reviewable changes (1)
  • src/apps/plots/urls.py
🧰 Additional context used
🧬 Code graph analysis (3)
tests/test_expiration.py (1)
tests/test_post_get.py (1)
  • _generate_key (142-153)
src/apps/plots/views.py (1)
src/apps/plots/view_util.py (2)
  • get_plot_data (107-117)
  • store_plot_data (120-143)
src/apps/plots/view_util.py (1)
src/apps/plots/models.py (1)
  • PlotData (59-87)
🪛 Ruff (0.14.10)
tests/test_expiration.py

73-73: Probable use of requests call without timeout

(S113)


79-79: Probable use of requests call without timeout

(S113)


127-127: Probable use of insecure hash functions in hashlib: sha1

(S324)

tests/test_post_get.py

124-124: Probable use of requests call without timeout

(S113)

🔇 Additional comments (8)
src/apps/plots/models.py (1)

15-16: LGTM on the data type simplification.

The consolidation to HTML-only data types aligns with the PR objectives. Retaining the data_type field in the model for backward compatibility is a reasonable approach.

src/apps/plots/view_util.py (1)

107-117: LGTM on the simplified data retrieval.

The removal of data_type parameter and per-type validation logic correctly aligns with the HTML-only consolidation. The length check before accessing the first element is appropriate.

tests/test_expiration.py (1)

107-113: LGTM on updated purge assertions.

The assertion updates from 2 to 1 correctly reflect that only one non-expired run should remain after purging (the run with run_id=12345, since run_id=12346 was created with an expiration date 3 years in the past).

tests/test_post_get.py (1)

122-139: LGTM on simplified test cases.

The test simplifications correctly reflect the removal of JSON endpoints and user-data workflows. The unauthorized and session tests now focus on the remaining HTML upload functionality.

src/apps/plots/views.py (4)

10-17: LGTM on updated imports.

The import changes correctly reflect the simplified data handling: JsonResponse removed, DATA_TYPES imported from models for consistent type handling.


54-63: LGTM on simplified HTML retrieval.

The update_as_html view now correctly calls get_plot_data without the data_type parameter, aligning with the simplified view_util function.


66-84: LGTM on simplified storage logic.

The _store function correctly:

  • Uses DATA_TYPES["html"] for consistent type handling
  • Maintains expiration date functionality
  • Returns 400 for missing file data

The removal of as_user branching and JSON-specific logic cleanly simplifies the code.


87-94: LGTM on simplified upload endpoint.

The upload_plot_data view now directly delegates to _store without the as_user parameter, which aligns with the removal of user-data upload functionality.

Copy link
Collaborator

@backmari backmari left a comment

Choose a reason for hiding this comment

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

This PR removes obsolete JSON handling from Live Data Server. Looks good 👌

@darshdinger darshdinger merged commit a4f14be into next Jan 8, 2026
4 checks passed
@darshdinger darshdinger deleted the ewm14160_remove_obsolete_option branch January 8, 2026 20:10
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.

2 participants