[SERVER-43613] "FieldPath cannot be constructed with empty string (40352)" message does not refer to user input Created: 24/Sep/19  Updated: 06/Mar/23

Status: Backlog
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Oleg Pudeyev (Inactive) Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to RUBY-1945 Prohibit distinct(nil) call as server... Closed
Assigned Teams:
Query Optimization
Participants:

 Description   

Our test performing a distinct(nil) operation began failing today with the following message:

Mongo::Error::OperationFailure: FieldPath cannot be constructed with empty string (40352) (on localhost:27017, attempt 1) (on localhost:27017, attempt 1)

This is the line of code that is failing:

          view.distinct(nil)

... which constructs the following command document:

        def distinct(field_name, opts = {})
          cmd = { :distinct => collection.name,
                  :key => field_name.to_s,
                  :query => filter }

The error is generated thusly:

FieldPath::FieldPath(std::string inputPath)
    : _fieldPath(std::move(inputPath)), _fieldPathDotPosition{string::npos} {
    uassert(40352, "FieldPath cannot be constructed with empty string", !_fieldPath.empty());
    uassert(40353, "FieldPath must not end with a '.'.", _fieldPath[_fieldPath.size() - 1] != '.');

The error returned by the server to the client/driver should indicate what was wrong in the input provided to the server. In this case, I expect the error to resemble something like "Empty `key` is not allowed with `distinct`", referring to the input provided to the server. The actual error references "FieldPath" which is an internal implementation aspect of the server and not anything a user/application/driver knows.



 Comments   
Comment by Shane Harvey [ 06/Mar/23 ]

As pointed out in this community forum post, this error also happens when trying to use a projection with an empty string field:

>>> client.t.t.find_one({}, projection={"": 1})
Traceback (most recent call last):
...
pymongo.errors.OperationFailure: FieldPath cannot be constructed with empty string, full error: {'ok': 0.0, 'errmsg': 'FieldPath cannot be constructed with empty string', 'code': 40352, 'codeName': 'Location40352', '$clusterTime': {'clusterTime': Timestamp(1678131148, 1), 'signature': {'hash': b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'keyId': 0}}, 'operationTime': Timestamp(1678131148, 1)}

Generated at Thu Feb 08 05:03:37 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.