Bug 250699

Summary: Preview tab is blank for new issues
Product: Services Reporter: Mikhail Teterin <mi>
Component: Bug TrackerAssignee: Bugmeister <bugmeister>
Status: Open ---    
Severity: Affects Many People CC: 000.fbsd, danfe, freebsd, grahamperrin, grahamperrin, grembo, lwhsu, pi, yasu
Priority: --- Keywords: needs-patch, needs-qa
Version: unspecified   
Hardware: Any   
OS: Any   
See Also: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=235238

Description Mikhail Teterin freebsd_committer freebsd_triage 2020-10-28 17:59:51 UTC
As I type this very description, I can click on the Preview-tab to see, what the typed text will look like.

Unfortunately, the Preview is empty -- the message "Generating preview" flashes briefly, but then disappears... It used to work, but does not any more :(
Comment 1 Li-Wen Hsu freebsd_committer freebsd_triage 2020-10-28 18:05:19 UTC
I just tested it and it works for me. I did a quick check and found it is not generated locally but through sending a request to:

https://bugs.freebsd.org/bugzilla/jsonrpc.cgi

Can you open your browser's traffic inspector and check the request/response when clicking on the preview tab?
Comment 2 Mikhail Teterin freebsd_committer freebsd_triage 2020-10-28 18:10:58 UTC
(In reply to Li-Wen Hsu from comment #1)
> I just tested it and it works for me

I use Firefox 79.0 -- do you? Ad-blocker is disabled on FreeBSD.org.

> Can you open your browser's traffic inspector

I see POST-requests to jsonrpc.cgi -- type "XHR" -- and the HTTP-status is 200...


General
Request URL:https://bugs.freebsd.org/bugzilla/jsonrpc.cgi
Request Method:POST
Status Code:200
Started:14:07:09
Total time:772.00 ms
Request headers
Accept:*/*
Accept-Encoding:gzip, deflate, br
Accept-Language:uk,en-US;q=0.8,en;q=0.5,ru;q=0.3
Connection:keep-alive
Content-Length:110
Content-Type:application/json
Cookie:Bugzilla_login=6XX2; Bugzilla_logincookie=XXXXX; LASTORDER=bug_status%2Cpriority%2Cassigned_to%2Cbug_id; VERSION-Ports%20%26%20Packages=Latest; VERSION-Services=unspecified; TUI=attachment_text_field=0&history_query=0&people_query=0&information_query=0&custom_search_query=0&custom_search_advanced=0&expert_fields=0
DNT:1
Host:bugs.freebsd.org
Origin:https://bugs.freebsd.org
Referer:https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=250699
User-Agent:Mozilla/5.0 (X11; FreeBSD amd64; rv:79.0) Gecko/20100101 Firefox/79.0
X-Requested-With:XMLHttpRequest
Response headers
Accept-Ranges:bytes
Age:0
Connection:keep-alive
Content-Type:application/json; charset=UTF-8
Date:Wed, 28 Oct 2020 18:07:10 GMT
Server:Apache
Strict-transport-security:max-age=604800
Transfer-Encoding:chunked
Via:1.1 wfe0.nyi.FreeBSD.org
X-Cache:MISS
X-content-type-options:nosniff, nosniff
X-frame-options:SAMEORIGIN, SAMEORIGIN
X-Varnish:766704054
X-xss-protection:1; mode=block, 1; mode=block
Other
Initiator:
From cache:false
Comment 3 Michael Gmelin freebsd_committer freebsd_triage 2021-03-01 19:35:42 UTC
This only happens when entering new bugs, not when commenting on existing bugs.

I was able to reproduce the calls to jsonrpc.cgi on the command line using curl. It seems like the problem is the missing "id" parameter in the request (again, I crossed out tokens and ids).

1. Send no id => get null in return.

curl -b "Bugzilla_login=12345; Bugzilla_logincookie=xxx;" \
  -H "Content-Type: application/json" -H "Accept: */*" \
  -d '{"version":"1.1","method":"Bug.render_comment","params":{"Bugzilla_api_token":"yyy","text":"test22"}}' \
  https://bugs.freebsd.org/bugzilla/jsonrpc.cgi
{"version":"1.1","result":{"html":null}}

2. Send id == 0 => same result

curl -b "Bugzilla_login=12345; Bugzilla_logincookie=xxx;" \
  -H "Content-Type: application/json" -H "Accept: */*" \
  -d '{"version":"1.1","method":"Bug.render_comment","params":{"Bugzilla_api_token":"yyy","id":"0","text":"test22"}}' \
  https://bugs.freebsd.org/bugzilla/jsonrpc.cgi
{"version":"1.1","result":{"html":null}}

3. Send unknown ID => error

curl -b "Bugzilla_login=12345; Bugzilla_logincookie=xxx;" \
  -H "Content-Type: application/json" -H "Accept: */*" \
  -d '{"version":"1.1","method":"Bug.render_comment","params":{"Bugzilla_api_token":"yyy","id":"9999999","text":"test22"}}' \
  https://bugs.freebsd.org/bugzilla/jsonrpc.cgi
{"error":{"message":"Bug #9999999 does not exist.","name":"JSONRPCError","code":101},"version":"1.1"

4. Send known ID => works

curl -b "Bugzilla_login=12345; Bugzilla_logincookie=xxx;" \
  -H "Content-Type: application/json" -H "Accept: */*" \
  -d '{"version":"1.1","method":"Bug.render_comment","params":{"Bugzilla_api_token":"yyy","id":"1","text":"test22"}}' \
  https://bugs.freebsd.org/bugzilla/jsonrpc.cgi
{"version":"1.1","result":{"html":"test22"}}

I guess the solution is to correct jsonrpc.cgi to work without a bug id being passed in (as it is the case with new bugs).

A quick-fix/workaround could be to change the new bug page to pass in "id":"1" (simply changing 'onclick="show_comment_preview()"' to 'onclick="show_comment_preview(1)"' might do the trick - I haven't tested this, but the javascript source of show_comment_preview indicates that this might work).
Comment 4 Mikhail Teterin freebsd_committer freebsd_triage 2021-03-07 18:36:19 UTC
*** Bug 235238 has been marked as a duplicate of this bug. ***
Comment 5 Li-Wen Hsu freebsd_committer freebsd_triage 2021-10-12 08:12:25 UTC
*** Bug 259092 has been marked as a duplicate of this bug. ***
Comment 6 Michael Gmelin freebsd_committer freebsd_triage 2021-10-12 09:47:09 UTC
Hi lwhsu,

Have you considered applying the workaround I suggested? If it works, it's as easy as changing one character:

> A quick-fix/workaround could be to change the new bug page
> to pass in "id":"1" (simply changing 'onclick="show_comment_preview()"'
> to 'onclick="show_comment_preview(1)"' might do the trick - I haven't
> tested this, but the javascript source of show_comment_preview
> indicates that this might work).

(and if it doesn't, it shouldn't make things worse).

Best
Michael
Comment 7 Michael Gmelin freebsd_committer freebsd_triage 2022-01-02 17:26:43 UTC
(In reply to Michael Gmelin from comment #6)

Ping, it would be really nice to have preview back.
Comment 8 Graham Perrin freebsd_committer freebsd_triage 2022-02-03 00:53:17 UTC
Gentle bump. 

A fix for this will be greatly appreciated; it's always a frustration when preview is impossible. 

Cross-reference: bug 261686 comment 0
Comment 9 Kubilay Kocak freebsd_committer freebsd_triage 2022-02-08 03:06:34 UTC
grembo identified an upstream commit [1] that resolves the issue but doesn't appear to have been backported to 5.[01].x branches, or our local skin [2] has not picked up the underlying change and needs to.

If the root cause is in our FreeBSD skin, a PR against that in our github repo would be appreciated, otherwise we'll need to apply a patch to the bugzilla50 port to carry the bugfix.

We'll want to get this done with a simultaneous upstream base update (single deployment), which may need to be coordinated with clusteradm as configurations are under management, in the event they are needed.

[1] https://github.com/bugzilla/bugzilla/commit/017ef4f703815614905bfb39873dae2dce2390d9
[2] https://github.com/freebsd/bugzilla/blob/freebsd-local/skins/contrib/FreeBSD/global.css
Comment 10 Michael Gmelin freebsd_committer freebsd_triage 2022-02-08 10:47:42 UTC
(In reply to Kubilay Kocak from comment #9)

> grembo identified an upstream commit [1] that resolves the issue

Unfortunately that commit can't be the culprit, as:
- looking at the page source, it seems like it was applied (also,it's
  from 2014 and things worked in the meantime)
- It doesn't match the analysis in comment #3

In the meantime, I verified that the workaround I suggested in #3
actually works. You can try it for yourself in the browser
(I tried in chromium):

1. Open a new bug
2. Open developer tools (F12 or right-click inspect page)
3. Click "Sources"
4. Unfold "data/assets"
5. There should be three assets, select the one that starts
   with ";/* js/attachment.js */ function validateAttachmentForm"
   (simply click through them until you find that one).
6. Go to line 1229, which reads "id: bug_id," and change it to
   "id: bug_id ? bug_id : 1"
7. Press CTRL-S to apply the change
8. Change the text in the Comment field and click Preview again
9. Perceive it working

This corresponds to this line in the bugzilla sources:
https://github.com/bugzilla/bugzilla/blob/4f4afbd8dd029554fdc075d24c659e9be5d1ebb8/js/field.js#L1081

This means that working around this problem, until someone has the
time (and access permissions) to analyze why sending in a null
bug_id doesn't work, is as simple as applying this patch to fields.js:

--- js/field.js.orig   2022-02-08 11:38:47.000000000 +0100
+++ js/field.js    2022-02-08 11:39:14.816160000 +0100
@@ -1078,7 +1078,7 @@
         method: 'Bug.render_comment',
         params: {
             Bugzilla_api_token: BUGZILLA.api_token,
-            id: bug_id,
+            id: bug_id ? bug_id : 1,
             text: comment.value
         }
     })

Of course, it would be better to figure out where in the stack this breaks (maybe something is filtering queries that don't contain bug_id=<number>,
maybe it's a bug in perl, hard to tell without seeing the actual sources
deployed/configs).
Comment 11 Michael Gmelin freebsd_committer freebsd_triage 2022-03-26 13:09:11 UTC
Ping again - there is an analysis and people willing to help, but no feedback.
Comment 12 Kubilay Kocak freebsd_committer freebsd_triage 2022-03-31 00:12:01 UTC
(In reply to Michael Gmelin from comment #11)

From comment 9 

> If the root cause is in our FreeBSD skin, a PR against that in our github repo
> would be appreciated, otherwise we'll need to apply a patch to the bugzilla50
> port to carry the bugfix.

If the upstream commit is indeed 'not' the bugfix (happy to accept your analysis) and there have actually been multiple "Comment Preview tabs broken in New bug page" bugs) then ...

Can you create a new ports issue (blocking this one) for "devel/bugzilla50" that adds a patch to js/fields.js with the fix, including upstream commit/title references please.

I can make the change locally until the updated port is deployed. I can't recall if the bugzilla jail is under config management where changes are reset every <period>, but that may be the case.
Comment 13 Michael Gmelin freebsd_committer freebsd_triage 2022-03-31 07:41:23 UTC
(In reply to Kubilay Kocak from comment #12)

Some information on our installation would be helpful, especially:
1. Which version is installed
2. Were the instructions from https://github.com/freebsd/bugzilla used
   for installation?
3. What webserver configs are in front of it?

The js change is a hack to make it work, it's not a permanent fix I would attempt to upstream. If we really want to get to the bottom of this and get a proper patch, we probably have to reproduce the setup (and have some certainty that a fix will be deployed within due time).
Comment 14 Michael Gmelin freebsd_committer freebsd_triage 2022-03-31 13:39:54 UTC
(In reply to Kubilay Kocak from comment #12)

As a data point:
I installed a local copy of bugzilla from ports (bugzilla 5.0.4_2) and untarred  FreeBSD's Skin from github on top. In that setting, preview seems to work just fine. Maybe there are some local alterations (in code or config) that filter requests without an id parameter?

So to figure out more, one would need to know what is installed. Otherwise, my workaround from above would work as well, but someone with the access permissions to do that might also be in a position to check/understand what is actually going on.

I don't think there is anything to be upstreamed here.
Comment 15 Kubilay Kocak freebsd_committer freebsd_triage 2022-04-01 00:20:56 UTC
(In reply to Michael Gmelin from comment #14)

It's very unlikely there are local changes (not matching github/freebsd-bugzilla).

Only thing I can think of that might be implicated is the environment in front of bugzilla. FreeBSD's Bugzilla instance is run under apache, with varnish and various frontend'ey stuff in front, or there may be some URL redirection/normalization stuff happening.

clusteradm@ may know more. 

I'm happy to debug with you on IRC or elsewhere realtime. I've also pinged upstream with this issue id to get their thoughts.
Comment 16 Li-Wen Hsu freebsd_committer freebsd_triage 2022-04-16 21:35:25 UTC
It's unlikely the issue of the front servers of bugzilla app server.  I tried to replay the request directly on the bugzilla app server, and still got null in response.


$ curl -v -H 'Host: bugs.freebsd.org' 'http://localhost/bugzilla/jsonrpc.cgi' -X POST -H 'User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:99.0) Gecko/20100101 Firefox/99.0' -H 'Accept: */*' -H 'Accept-Language: en-US,zh-TW;q=0.7,en;q=0.3' -H 'Accept-Encoding: gzip, deflate, br' -H 'X-Requested-With: XMLHttpRequest' -H 'Content-Type: application/json' -H 'Origin: https://bugs.freebsd.org' -H 'DNT: 1' -H 'Connection: keep-alive' -H 'Referer: https://bugs.freebsd.org/bugzilla/enter_bug.cgi?product=Other' -H 'Cookie: Bugzilla_login=... Bugzilla_logincookie=...; LASTORDER=bug_id; VERSION-Ports%20%26%20Packages=Latest; DEFAULTFORMAT=advanced; VERSION-Base%20System=CURRENT; VERSION-Services=unspecified; VERSION-Documentation=Latest; TUI=expert_fields=1&attachment_text_field=0&history_query=1&people_query=1&information_query=1&custom_search_query=1&custom_search_advanced=0; __utma=1.1750622577.1624390923.1626147426.1626157043.41' -H 'Sec-Fetch-Dest: empty' -H 'Sec-Fetch-Mode: cors' -H 'Sec-Fetch-Site: same-origin' --data-raw '{"version":"1.1","method":"Bug.render_comment","params":{"Bugzilla_api_token":"...","text":"asdasdasda"}}'
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 127.0.0.1:80...
* TCP_NODELAY set
* Connected to localhost (127.0.1.5) port 80 (#0)0
> POST /bugzilla/jsonrpc.cgi HTTP/1.1
> Host: bugs.freebsd.org
> User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:99.0) Gecko/20100101 Firefox/99.0
> Accept: */*
> Accept-Language: en-US,zh-TW;q=0.7,en;q=0.3
> Accept-Encoding: gzip, deflate, br
> X-Requested-With: XMLHttpRequest
> Content-Type: application/json
> Origin: https://bugs.freebsd.org
> DNT: 1
> Connection: keep-alive
> Referer: https://bugs.freebsd.org/bugzilla/enter_bug.cgi?product=Other
> Cookie: Bugzilla_login=...; Bugzilla_logincookie=...; LASTORDER=bug_id; VERSION-Ports%20%26%20Packages=Latest; DEFAULTFORMAT=advanced; VERSION-Base%20System=CURRENT; VERSION-Services=unspecified; VERSION-Documentation=Latest; TUI=expert_fields=1&attachment_text_field=0&history_query=1&people_query=1&information_query=1&custom_search_query=1&custom_search_advanced=0; __utma=1.1750622577.1624390923.1626147426.1626157043.41
> Sec-Fetch-Dest: empty
> Sec-Fetch-Mode: cors
> Sec-Fetch-Site: same-origin
> Content-Length: 112
> 
* upload completely sent off: 112 out of 112 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Date: Sat, 16 Apr 2022 21:28:36 GMT
< Server: Apache
< Strict-transport-security: max-age=604800
< X-content-type-options: nosniff
< X-frame-options: SAMEORIGIN
< X-xss-protection: 1; mode=block
< Keep-Alive: timeout=5, max=100
< Connection: Keep-Alive
< Transfer-Encoding: chunked
< Content-Type: application/json; charset=UTF-8
< 
* Connection #0 to host localhost left intact
{"result":{"html":null},"version":"1.1"}
Comment 17 Graham Perrin freebsd_committer freebsd_triage 2022-09-17 09:47:33 UTC
> triple-check the Description

-- is now the first DO in Bugzilla/DosAndDonts

<https://wiki.freebsd.org/action/info/Bugzilla/DosAndDonts?action=diff&rev2=79&rev1=78>
Comment 18 Alexey Dokuchaev freebsd_committer freebsd_triage 2023-04-16 14:28:59 UTC
Any progress on this?  Preview still does not work when filing new PR as of today.
Comment 19 Miroslav Lachman 2024-02-25 19:58:53 UTC
After almost a year, is there any progress?
Comment 20 Mark Linimon freebsd_committer freebsd_triage 2024-02-27 22:36:33 UTC
(In reply to Miroslav Lachman from comment #19)
I have not yet taken the time to look at this one.

Most of my Bugzilla time the last few months has been trying to bring our git
repo back up to date with what is actually deployed on production.