Bug #102595 Internal error: JSON wrapper: unexpected type from json_unquote json_extract
Submitted: 14 Feb 2021 23:00 Modified: 15 Feb 2021 7:41
Reporter: Dave Pullin (Basic Quality Contributor) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: JSON Severity:S3 (Non-critical)
Version:5.7.31, 5.7.33 OS:CentOS (CentOS Linux release 7.6.1810 (Core))
Assigned to: CPU Architecture:Any

[14 Feb 2021 23:00] Dave Pullin
Description:
I assume Internal Error are always a bug, not my fault.
It is generated in "json_unquote(y);" when y is null returned by json_extract.
There's a good chance it is related to https://bugs.mysql.com/102594

mysql> delimiter ^
mysql> create database if not exists bug^
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> drop function if exists bug.func^
Query OK, 0 rows affected (0.00 sec)

mysql> create function bug.func()returns boolean
    -> begin
    ->      declare y json;
    ->      declare z json;
    ->      SET y= json_extract(json_object(),"$.x"); 
    ->      set z = json_unquote(y);
    ->    return "x";
    -> end;^
Query OK, 0 rows affected (0.00 sec)

mysql> select bug.func()^
ERROR 1815 (HY000): Internal error: JSON wrapper: unexpected type

How to repeat:
delimiter ^
create database if not exists bug^
drop function if exists bug.func^
create function bug.func()returns boolean
begin
     declare y json;
     declare z json;
     SET y= json_extract(json_object(),"$.x"); 
     set z = json_unquote(y);
   return "x";
end;^
select bug.func()^
[15 Feb 2021 7:41] MySQL Verification Team
Hello Dave,

Thank you for the report and test case.
Verified as described.

regards,
Umesh