nodejs-datastore
nodejs-datastore copied to clipboard
Do not clutter the logs with warnings in prod environment
The following code
const companyQuery = query
.filter('name', 'Google')
.filter('size', '<', 400);
will print a warning:
process.emitWarning(
'Providing Filter objects like Composite Filter or Property Filter is recommended when using .filter'
);
First I don't think there should be any warning in a prod environment.
One way js libraries check for prod environemnt is to check if the NODE_ENV environment variable is set to production - see the express docs for ref.
Also my understanding is that the warning is there because of nested composite filters. I don't think there should be any warnings in a simple case, that is:
const companyQuery = query.filter('name', 'Google');
should probably not generate a warning even in dev env.
/cc @danieljbruce
Datastore in Python emits this warning too so whatever we end up doing there should probably be consistency across the board.
I am not familiar with Python warnings but it looks like you can at least filter the warnings
This is what I mean:
It would be great to filter out all the noise in my prod env.
Thanks!
What should be done not to get this warning when building a query with filters?
According to docs there are two ways of filtering a query, with operator and without (defaults to equals). So, how could we build and supply a Filter object?
It looks like the doc is not up to date. The filter method can now take objects. You can look at the tests for an example.
That being said I think using the legacy way (with and without operator) should still be supported and should not log a warning at least in production mode.
Using PropertyFilter eliminates the warning.
import { Datastore, PropertyFilter } from '@google-cloud/datastore'
const ds = new Datastore()
const query = ds.createQuery('Kind')
.filter(new PropertyFilter('foo', '=', 'bar'))
.filter(new PropertyFilter('baz', '=', 'quux'))
@efossvold read my initial message. I said I don't think we should be forced to do that for simple case because there is no point. Thanks for trying to help though.