Bug #92688 Year field in document returns error when used
Submitted: 5 Oct 2018 13:38 Modified: 6 Oct 2018 12:21
Reporter: Frederic Descamps Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Connectors: Document Store: DevAPI Severity:S3 (Non-critical)
Version:8.0.13 OS:Linux
Assigned to: CPU Architecture:Any

[5 Oct 2018 13:38] Frederic Descamps
Description:
A document with a field like Year provides error and cannot be used in filters, fields selection or sort.
The error is with python and js in the Shell.

How to repeat:
Py db.mybooks.find()
[
    {
        "Authors": [
            "David Stokes"
        ], 
        "ISBN-13": "9781260135442", 
        "Language": "en", 
        "Publisher": "McGraw-Hill Education", 
        "Title": "MySQL And JSON: A Practical Programming Guide", 
        "Year": "2018", 
        "_id": "00005bb732b60000000000000024"
    }, 
    {
        "Authors": [
            "Charles Bell"
        ], 
        "ISBN-13": "9781484227244", 
        "Language": "en", 
        "Publisher": "Apress", 
        "Title": "Introducing The MySQL 8 Document Store", 
        "Year": "2018", 
        "_id": "00005bb732b60000000000000027"
    }, 
    {
        "Authors": [
            "Jesper Wisborg Krogh"
        ], 
        "ISBN-13": "9781484236932", 
        "Language": "en", 
        "Publisher": "Apress", 
        "Title": "MySQL Connector/Python Revealed", 
        "Year": "2018", 
        "_id": "00005bb732b60000000000000028"
    }, 
    {
        "Authors": [
            "Charles Bell"
        ], 
        "ISBN-13": "9781484238844", 
        "Language": "en", 
        "Publisher": "Apress", 
        "Title": "Introducing InnoDB Cluster", 
        "Year": "2018", 
        "_id": "00005bb732b60000000000000029"
    }, 
    {
        "Authors": [
            {
                "name": "Jesper Wisborg Krogh"
            }, 
            {
                "name": "Mikiya Okuno"
            }
        ], 
        "ISBN-13": "9781484229811", 
        "Language": "en", 
        "Title": "Pro MySQL NDB Cluster", 
        "Year": "2018", 
        "_id": "00005bb732b6000000000000002d", 
        "publisher": "Apress"
    }
]

Py db.mybooks.find().fields('Title','Year').sort('Year').limit(1)
Traceback (most recent call last):
  File "<string>", line 1, in <module>
SystemError: RuntimeError: CollectionFind.fields: Expected token at position 1 but no tokens left.

Suggested fix:
Workaround using backticks: 

Py db.mybooks.find().fields('Title','`Year`').sort('`Year`').limit(1)
[
    {
        "Title": "Understanding MySQL Internals", 
        "`Year`": "2007"
    }
]
1 document in set (0.0006 sec

But it should work without this hack.
[6 Oct 2018 12:21] MySQL Verification Team
Hello Frederic,

Thank you for the report and test case.

regards,
Umesh