Skip to content

Always set Results #6741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 28 additions & 27 deletions api/src/org/labkey/api/data/DataRegion.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.junit.Assert;
import org.junit.Test;
import org.labkey.api.collections.BoundMap;
import org.labkey.api.collections.CaseInsensitiveHashMap;
import org.labkey.api.collections.ResultSetRowMapFactory;
import org.labkey.api.collections.RowMap;
import org.labkey.api.collections.Sets;
Expand Down Expand Up @@ -2065,36 +2064,38 @@ private void renderInputForm(RenderContext ctx, HtmlWriter out)

private void renderUpdateForm(RenderContext ctx, HtmlWriter out)
{
TableViewForm viewForm = ctx.getForm();
Map<String, Object> valueMap = ctx.getRow();
LinkedHashMap<FieldKey, ColumnInfo> selectKeyMap = getSelectColumns();
if (null == valueMap)
try
{
if (!hasPermission(ctx, ReadPermission.class))
throw new UnauthorizedException();

valueMap = new CaseInsensitiveHashMap<>();

TableInfo tinfoMain = getTable();
Collection<Map<String, Object>> maps = new TableSelector(tinfoMain, selectKeyMap.values(), new PkFilter(tinfoMain, viewForm.getPkVals()), null).getMapCollection();
if (!maps.isEmpty())
valueMap.putAll(maps.iterator().next());

//For updates, the valueMap is the OLD version of the data.
//If there is no old data, we reselect to get it
if (null != viewForm.getOldValues())
TableViewForm viewForm = ctx.getForm();
Map<String, Object> valueMap = ctx.getRow();
LinkedHashMap<FieldKey, ColumnInfo> selectKeyMap = getSelectColumns();
if (null == valueMap)
{
//UNDONE: getOldValues() sometimes returns a map and sometimes a bean, this seems broken to me (MAB)
Object old = viewForm.getOldValues();
if (old instanceof Map m)
valueMap.putAll(m);
else
valueMap.putAll(new BoundMap(old));
if (!hasPermission(ctx, ReadPermission.class))
throw new UnauthorizedException();

// For update the Results holds the current version of the data.
// The posted values (for reshow) are help by TableViewForm (RenderContext.getForm()). see DisplayColumn.getInputValue()
TableInfo tinfoMain = getTable();
var results = new TableSelector(tinfoMain, selectKeyMap.values(), new PkFilter(tinfoMain, viewForm.getPkVals()), null).getResults(true);
// NOTE MissingValueDisplayColumn does not work without Results, it relies on using .get(FieldKey) that it enables
if (results.next())
{
ctx.setResults(results);
ctx.setRow(results.getRowMap());
}
}
ctx.setRow(valueMap);
}

renderForm(ctx, out);
renderForm(ctx, out);
}
catch (SQLException e)
{
throw new RuntimeSQLException(e);
}
finally
{
ResultSetUtil.close(ctx.getResults());
}
}

/**
Expand Down