Skip to content

Query result during transaction will be blank if there's already a query with a similar "group" defined. #259

@willhoney7

Description

@willhoney7

Describe the bug

In a pretty specific situation, a query result will return BLANK during a transaction. You can see it in the code below (and in the linked stackblitz).

To reproduce:

  • define a first query with a group keyword.
  • start a transaction
  • define another query (on the same table) with a group keyword (can be a different column!)
  • call getResultTable and see that it's blank
  • finish the transaction
  • call getResultTable and see that it does return a value

See the following code (and linked reproduction).

const store = createMergeableStore().setSchema(
	{
		records: {
			account: { type: 'string' },
			amount: { type: 'number' },
			decimals: { type: 'number' },
		},
	},
	{}
);
store.setTables({
	records: generateDummyData(),
});

const queries = createQueries(store);

queries.setQueryDefinition('budgetTotal', 'records', (keywords) => {
	keywords.select('account');
	keywords.select('amount');
	// if you comment out the group line here, the second query will work correctly.
	keywords.group('amount', 'avg');
});

if (enableTransaction) {
	store.startTransaction();
}

const queryId = `otherQuery`;
queries.setQueryDefinition(queryId, 'records', (keywords) => {
	keywords.select('amount');
	keywords.where('account', '1');
	// or if you remove group here, this query will work correctly.
	// also has issues if you group by a completely different column
	keywords.group('amount', 'sum');
});

console.log('first', JSON.stringify(queries.getResultTable(queryId))); // BLANK!
console.log('second', JSON.stringify(queries.getResultTable(queryId))); // BLANK!

if (enableTransaction) {
	store.finishTransaction();
	console.log(
		'after transaction',
		JSON.stringify(queries.getResultTable(queryId))
	);
}

Your Example Website or App

https://stackblitz.com/edit/vitejs-vite-jec8c4bm?file=src%2Fcounter.ts

Expected behavior

I would expect the query to return correct data, even mid-transaction.

Platform

  • OS: macOS
  • Browser: Brave
  • Version: 6.3

Metadata

Metadata

Assignees

Labels

as designedI think this is how it is supposed to work...more info requiredCould you answer a few extra questions to clarify?

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions