94041c12e043016875ebd340568bda0ccaf122f6
lrnassar
  Wed Jul 8 13:53:22 2026 -0700
Add db= to cross-CGI hgTracks/hgTrackUi/hgc links to prevent wrong-assembly errors. refs #37840

Completes the incomplete work from #26892: links from the browser to a different
CGI omitted db=, so the target CGI fell back to the cart's db (often wrong),
producing "Can't find <track> in track database <db>" errors and broken shared
links. Adds the current-assembly db to link builders across hgTracks
(chromGraphTrack, expRatioTracks, config ruler and per-track configure links,
variation), hgVai, hgFileUi, hgGtexTrackSettings, hgBlat, hgGene, hgNear, the
barChart/GTEx faceted UI (facetedBar, barChartUi, gtexUi), and the hgTrackUi
group-configure link.

diff --git src/hg/hgTracks/config.c src/hg/hgTracks/config.c
index 1a59b8fa9bb..28257e86458 100644
--- src/hg/hgTracks/config.c
+++ src/hg/hgTracks/config.c
@@ -355,33 +355,33 @@
      * confusing to the javascript submit() function.
      */
     char submitName[256];
     safef(submitName, sizeof(submitName), "%sSubmit", group->name);
     cgiMakeButtonWithMsg(submitName, "Submit","Submit your selections and view them in the browser");
     hPrintf("</td></tr></table>\n");
     hPrintf("</TH></TR>\n");
 
     /* First non-CT, non-hub group gets ruler. */
     if (!showedRuler && !isHubTrack(group->name) &&
                 differentString(group->name, "user"))
 	{
         showedRuler = TRUE;
         hPrintf("<TR %sid='%s-0'>",(isOpen ? "" : "style='display: none'"), group->name);
 	hPrintf("<TD>");
-        hPrintf("<A HREF=\"%s?%s=%s&c=%s&g=%s&hgTracksConfigPage=configure\">", hgTrackUiName(),
+        hPrintf("<A HREF=\"%s?%s=%s&db=%s&c=%s&g=%s&hgTracksConfigPage=configure\">", hgTrackUiName(),
                 cartSessionVarName(), cartSessionId(cart),
-                chromName, RULER_TRACK_NAME);
+                database, chromName, RULER_TRACK_NAME);
         hPrintf("%s</A>", RULER_TRACK_LABEL);
 	hPrintf("</TD><TD>");
 	hTvDropDownClassVisOnlyWithLabel("ruler", rulerMode, FALSE,
 		rulerMode ? "normalText trackVis" : "hiddenText trackVis",
 		NULL, RULER_TRACK_LABEL);
 	hPrintf("</TD><TD>");
 	hPrintf("Chromosome position in bases.  (Clicks here zoom in 3x)");
 	hPrintf("</TD></TR>\n");
 	}
     /* Scan track list to determine which supertracks have visible member
      * tracks, and to insert a track in the list for the supertrack.
      * Sort tracks and supertracks together by priority */
     makeGlobalTrackHash(trackList);
     groupTrackListAddSuper(cart, group, superHash, trackHash);
 
@@ -429,35 +429,35 @@
     for (tr = group->trackList; tr != NULL; tr = tr->next)
         {
         struct track *track = tr->track;
         struct trackDb *tdb = track->tdb;
 
         hPrintf("<TR %sid='%s-%d'>",(isOpen ? "" : "style='display: none;'"),
                 group->name, rowCount++);
         hPrintf("<TD NOWRAP>");
         if (tdbIsSuperTrackChild(tdb))
             /* indent members of a supertrack */
             hPrintf("&nbsp;&nbsp;&nbsp;&nbsp;");
 
         hPrintIcons(tdb);
 
         if (track->hasUi)
-            hPrintf("<A TITLE='%s%s...' HREF='%s?%s=%s&g=%s&hgTracksConfigPage=configure'>",
+            hPrintf("<A TITLE='%s%s...' HREF='%s?%s=%s&db=%s&g=%s&hgTracksConfigPage=configure'>",
                     tdb->parent ? "Part of super track: " : "Configure ",
                     tdb->parent ? tdb->parent->shortLabel : tdb->shortLabel,
                     hTrackUiForTrack(tdb->track),
-                    cartSessionVarName(), cartSessionId(cart), track->track);
+                    cartSessionVarName(), cartSessionId(cart), database, track->track);
         hPrintf(" %s", tdb->shortLabel);
         if (track->hasUi)
 	    hPrintf("</A>");
 	hPrintf("</TD><TD NOWRAP>");
         if (tdbIsSuperTrackChild(tdb))
             /* indent members of a supertrack */
             hPrintf("&nbsp;&nbsp;&nbsp;&nbsp;");
 
 	/* If track is not on this chrom print an informational
 	   message for the user. */
         if (tdbIsDownloadsOnly(tdb))    // No vis display for downloadsOnly
             hPrintf("<A TITLE='Downloadable files...' HREF='%s?%s=%s&g=%s'>Downloads</A>",
                     hgFileUiName(),cartSessionVarName(), cartSessionId(cart), tdb->track);
         else if (hTrackOnChrom(track->tdb, chromName))
 	    {