Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
14 changes: 13 additions & 1 deletion api/src/org/labkey/api/query/PdLookupForeignKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,19 @@ private TableInfo findTableInfo(Container container)
if (!(schema instanceof UserSchema))
return null;

_tableInfo = schema.getTable(_tableName, _containerFilter);
// GH Issue 1718: Resolving the lookup compiles a query, and Query.getTableInfo() points the environment container at that
// query's schema without putting it back. The fallback above resolves in the property descriptor's container,
// so without this a lookup to a query defined in a parent folder leaves every later consumer of the
// environment container -- filter clauses, for one -- believing the request was for that container.
Object previousContainer = QueryService.get().getEnvironment(QueryService.Environment.CONTAINER);
try
{
_tableInfo = schema.getTable(_tableName, _containerFilter);
}
finally
{
QueryService.get().setEnvironment(QueryService.Environment.CONTAINER, previousContainer);
}
return _tableInfo;
}

Expand Down
14 changes: 13 additions & 1 deletion api/src/org/labkey/api/query/QueryForeignKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,19 @@ public TableInfo getLookupTableInfo()
{
if (_table == null && getLookupSchema() != null)
{
TableInfo t = getLookupSchema().getTable(_tableName, getLookupContainerFilter());
// GH Issue 1718: Query.getTableInfo() points the environment container at the lookup query's schema and never
// restores it, so resolving a lookup to another container would leave every later consumer -- filter clauses,
// for one -- believing the request was for that container.
Object previousContainer = QueryService.get().getEnvironment(QueryService.Environment.CONTAINER);
TableInfo t;
try
{
t = getLookupSchema().getTable(_tableName, getLookupContainerFilter());
}
finally
{
QueryService.get().setEnvironment(QueryService.Environment.CONTAINER, previousContainer);
}
if (t == null)
{
LOG.debug("Failed to resolve lookup to {} in schema {} in container {} for user {}", _tableName, getLookupSchema().getSchemaPath(), getLookupSchema().getContainer().getPath(), getLookupSchema().getUser());
Expand Down
Loading