-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
ValueError: For an array_value, subvalues must either all be indexed or all excluded from indexes. #3152
Comments
Hi @thisbejim, First off, a disclaimer: I am not an expert in Datastore. That said, I am having a little trouble with a fix for your issue, and it would help if you could provide the code that you think should work. It makes sense to me that an empty array should not raise an exception complaining about mismatched index exclusion of its subelements. That said, I am having trouble making an empty array function at all. Here is our code that checks for consistency on index exclusion: if is_list:
exclude_values = set(value_pb.exclude_from_indexes
for value_pb in value_pb.array_value.values)
if len(exclude_values) != 1:
raise ValueError('For an array_value, subvalues must either '
'all be indexed or all excluded from '
'indexes.') At first I thought this was a simple fix; simply add def test_index_mismatch_ignores_empty_list(self):
from google.cloud.proto.datastore.v1 import entity_pb2
from google.cloud.datastore.helpers import _new_value_pb
_PROJECT = 'PROJECT'
_KIND = 'KIND'
_ID = 1234
entity_pb = entity_pb2.Entity()
entity_pb.key.partition_id.project_id = _PROJECT
entity_pb.key.path.add(kind=_KIND, id=_ID)
array_val_pb = _new_value_pb(entity_pb, 'baz')
array_pb = array_val_pb.array_value.values
entity = self._call_fut(entity_pb)
entity_dict = dict(entity)
self.assertIsInstance(entity_dict['baz'], list) This raises an exception when I try to run the function under test (which is
This makes me wonder if an empty array is even a valid option. (If I add a value to the array, it works fine.) Long story short: Can you provide code with what you are trying to do, and your expected result? |
Hi @lukesneeringer thanks for looking in to this. So to provide some context - I've built out an application using the node datastore client which does allow for writing and retrieving empty arrays, and I'm setting up a seperate python service just to handle my cron jobs / tasks. The application is a micro-blogging clone, so I have a
or
If I use a query with a projection to avoid retrieving the empty
|
Thanks. I will look into this further. |
@thisbejim Could you help me out by pulling this branch and telling me if it fixes your issue, or if you just get a different error? (I am asking under the assumption this is a quick check for you; if not, feel free to just say no.) |
I'm facing the same issue described here. I haven't tried the branch yet, but is there any workaround available? |
@alercunha The branch may be a path to a workaround, but it seems @lukesneeringer was looking for someone to vet the fix. |
I just tested the suggested fix and in my case it does work. Any help needed promoting this fix to be merged back to master? |
It happens to me only when there is an EMPTY indexed array. As a workaround, I added a placeholder value instead of keeping it empty. Is there any progress with fixing that? |
Hi guys! I'm facing the same issue and I use datastore in read-only mode so I can't do anything with original data. Any news about the fix @lukesneeringer @dhermes ? |
Facing the same issue in a critical moment. Any updates @lukesneeringer @dhermes ? |
@MeteKem @ishcherbakov Does the branch I had in place a few months ago solve your issue? If it is actually a valid fix, then I am happy to merge it. |
@lukesneeringer it did fix the issue in my case. |
@lukesneeringer It fixed the issue in my case too. |
Okay, it is now a pull request. :-) |
same issue here, is there a fix for this that's merged into some version of datastore client library ? |
I've forked the project just to do merge from upstream/master to the PR branch that contains this fix. You can clone my branch and install it manually if you like. So you would have to do:
|
thanks @alercunha but can't seem to be able to figure out the dependencies .... The script I am trying to run is as simple as this: import google.auth
from google.cloud import datastore
credentials, project = google.auth.default()
client = datastore.Client(project=project, credentials=credentials)
query = client.query(kind='Event')
res = query.fetch()
for item in res:
print(list(item.items())) any help to get this working with your patch would be greatly appreciated. |
Looks like some recent changes end up breaking certain dependencies. |
Luckily I tagged a version that was working fine a few days before.
|
@alercunha thank you! that worked! |
Still having this error with
|
Getting
ValueError: For an array_value, subvalues must either all be indexed or all excluded from indexes.
error when querying entities with empty arrays.Edit: I tried getting around this with projection queries where possible but I need to modify the entities after fetching them, which you can't do with the results of a projection query. So this is a pretty big issue as there is no way around it.
The text was updated successfully, but these errors were encountered: