Skip to content

Commit 588555f

Browse files
authored
fixes FPBASE-5EX (#395)
1 parent 7195102 commit 588555f

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

backend/proteins/views/microscope.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ def update_scope_report(request):
4444
if request.POST.get("action") == "update":
4545
outdated = request.POST.get("outdated")
4646
if outdated:
47-
outdated = json.loads(outdated)
47+
try:
48+
outdated = json.loads(outdated)
49+
except json.JSONDecodeError:
50+
outdated = None
4851
if scope_id:
4952
try:
5053
# this is throwing connection resets

frontend/src/js/ajax-sentry.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,23 @@
2020

2121
import * as Sentry from "@sentry/browser"
2222

23+
/**
24+
* Create URLSearchParams from an object, filtering out undefined/null values.
25+
* This mimics jQuery's $.param() behavior which skips undefined keys.
26+
*
27+
* @param {object} obj - Object to convert to URLSearchParams
28+
* @returns {URLSearchParams} - URLSearchParams with undefined/null values filtered out
29+
*/
30+
export function createFormData(obj) {
31+
const filtered = {}
32+
for (const [key, value] of Object.entries(obj)) {
33+
if (value !== undefined && value !== null) {
34+
filtered[key] = value
35+
}
36+
}
37+
return new URLSearchParams(filtered)
38+
}
39+
2340
/**
2441
* Determine if an error should be reported to Sentry
2542
* Override this function to customize filtering logic

frontend/src/js/scope_report.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Highcharts from "highcharts"
2-
import { fetchWithSentry } from "./ajax-sentry"
2+
import { createFormData, fetchWithSentry } from "./ajax-sentry"
33

44
const $ = window.jQuery // jQuery loaded from CDN
55

@@ -36,10 +36,7 @@ $.fn.extend({
3636
var SCOPE_ID = config.scopeID
3737
var SCOPE_URL = config.scopeURL
3838
var JOB_ID = null
39-
var OUTDATED
40-
if (config.outdated.length) {
41-
OUTDATED = config.outdated
42-
}
39+
var OUTDATED = config.outdated || []
4340
var interval = config.interval || 3500
4441
var FLUORS
4542
var REPORT
@@ -367,7 +364,7 @@ $.fn.extend({
367364
function check_status(next) {
368365
next = next || interval
369366
if (JOB_ID !== null) {
370-
const formData = new URLSearchParams({
367+
const formData = createFormData({
371368
action: "check",
372369
job_id: JOB_ID,
373370
csrfmiddlewaretoken: CSRF_TOKEN,
@@ -421,12 +418,12 @@ $.fn.extend({
421418
action = "cancel"
422419
}
423420

424-
const formData = new URLSearchParams({
421+
const formData = createFormData({
425422
action: action,
426423
scope_id: SCOPE_ID,
427424
csrfmiddlewaretoken: CSRF_TOKEN,
428425
job_id: JOB_ID,
429-
outdated: JSON.stringify(OUTDATED),
426+
outdated: OUTDATED.length ? JSON.stringify(OUTDATED) : null,
430427
})
431428

432429
fetchWithSentry("", {

0 commit comments

Comments
 (0)