Bug #81351 switching session type from classic to JS fails
Submitted: 9 May 2016 9:26 Modified: 1 Jun 2016 11:57
Reporter: Giuseppe Maxia (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Document Store: MySQL Shell Severity:S1 (Critical)
Version:1.0.3 OS:Any
Assigned to: Juan Rene Ramirez Monarrez CPU Architecture:Any

[9 May 2016 9:26] Giuseppe Maxia
Description:
When you start mysqlsh in JS mode and try to switch to SQL, you get an error, with an helpful message advising you to connect using the C/S protocol.

Instead, when you start in classic mode and want to switch to JS, there is no failure and no message, but you get errors only when trying to access JS classes:

$ mysqlsh --user=msandbox --sqlc --password=msandbox --port=5712 test
mysqlx: [Warning] Using a password on the command line interface can be insecure.
Creating a Classic Session to msandbox@localhost:5712/test
Default schema `test` accessible through db.

Welcome to MySQL Shell 1.0.3 Development Preview

Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type '\help', '\h' or '\?' for help.

Currently in SQL mode. Use \js or \py to switch the shell to a scripting language.
mysql-sql> \js
Switching to JavaScript mode...
mysql-js> db.tables
{
    "t1": <ClassicTable:t1>
}
mysql-js> t1=db.getTable('t1')
<ClassicTable:t1>
mysql-js> t1.select()
AttributeError: Invalid object member select at (shell):1:2
in t1.select()
     ^

How to repeat:
Start the shell in classic mode.
Change to JS mode
Try accessing a database object

Suggested fix:
The shell should either connect to the X-protocol port or refuse to switch to JS/Py.
[10 May 2016 4:09] Umesh Shastry
Hello Giuseppe,

Thank you for the report.
Verified as described.

Thanks,
Umesh
[31 May 2016 13:15] Erlend Dahl
Posted by devloper:

This is not a bug, what happens is that you are connecting using a classic
session, the API is very very limited when you do that.
 
 
 
CRUD operations are only available when you use a session through the
XProtocol (XSession or NodeSession)
 
 
 
Here you can see the error is caused because you are trying to use a function
that does not exist on a Classic Table
 
 
 
http://dev.mysql.com/doc/dev/mysqlsh-devapi/classmysh_1_1mysql_1_1_classic_table.html
[31 May 2016 13:28] Giuseppe Maxia
Thanks for your explanation, but I don't think you got my point. 
The issue is that switching to JS from a classic session should generate a meaningful error, while now the user is kept wondering why. 
If a proper connection in JS mode is impossible, the switch command should not work at all.
[2 Jun 2016 4:39] Alfredo Kojima
session.getTable() should indeed just return an error. The way to use JS in a classic session is through session.runSql()