{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaDB/MySQL.jl/issues/60","repository_url":"https://api.github.com/repos/JuliaDB/MySQL.jl","labels_url":"https://api.github.com/repos/JuliaDB/MySQL.jl/issues/60/labels{/name}","comments_url":"https://api.github.com/repos/JuliaDB/MySQL.jl/issues/60/comments","events_url":"https://api.github.com/repos/JuliaDB/MySQL.jl/issues/60/events","html_url":"https://github.com/JuliaDB/MySQL.jl/issues/60","id":176724462,"number":60,"title":"\"InitError: Method called with null connection\" when precompiling","user":{"login":"xqrongm","id":12205732,"avatar_url":"https://avatars.githubusercontent.com/u/12205732?v=3","gravatar_id":"","url":"https://api.github.com/users/xqrongm","html_url":"https://github.com/xqrongm","followers_url":"https://api.github.com/users/xqrongm/followers","following_url":"https://api.github.com/users/xqrongm/following{/other_user}","gists_url":"https://api.github.com/users/xqrongm/gists{/gist_id}","starred_url":"https://api.github.com/users/xqrongm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xqrongm/subscriptions","organizations_url":"https://api.github.com/users/xqrongm/orgs","repos_url":"https://api.github.com/users/xqrongm/repos","events_url":"https://api.github.com/users/xqrongm/events{/privacy}","received_events_url":"https://api.github.com/users/xqrongm/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-09-13T19:09:15Z","updated_at":"2016-09-14T04:23:36Z","closed_at":"2016-09-14T04:23:36Z","body":"Julia v0.4.6\r\nMySQL 0.0.2+ master\r\n\r\nThanks a lot for adding `__precompile__()`. I cloned the latest master with `__precompile__()` and wrote this module:\r\n```\r\n__precompile__()\r\nmodule test_mysql\r\n    using MySQL\r\n    db_conn = mysql_connect(\"localhost\", \"user\", \"password\", \"test_1ch\")\r\n    ms_df1 = mysql_execute(db_conn, \"select * from steps where id=2\")\r\n    function __init__()\r\n        global ms_df2 = mysql_execute(db_conn, \"select * from steps where id=2\")\r\n    end\r\nend # test_mysql\r\n```\r\nThen\r\n`using test_mysql`\r\n\r\nThis is the output:\r\n> INFO: Precompiling module MySQL...\r\n> INFO: Precompiling module test_mysql...\r\n> ERROR: InitError: Method called with null connection.\r\n>  in mysql_execute at E:\\for_programs\\julia_pkgs\\v0.4\\MySQL\\src\\handy.jl:144\r\n>  in __init__ at E:\\freelance\\applications\\010_qpcr\\Julia\\test_mysql.jl:7\r\n>  in _require_from_serialized at loading.jl:84\r\n>  in _require_from_serialized at loading.jl:109\r\n>  in require at loading.jl:235\r\n> during initialization of module test_mysql\r\n\r\nIt looks like the `db_conn` in `ms_df1 = mysql_execute(db_conn, \"select * from steps where id=2\")` was a valid connection (because no error was raised before `__init__` was called), while the `db_conn_` in `global ms_df2 = mysql_execute(db_conn, \"select * from steps where id=2\")` becomes a null connection for some reason I don't understand.\r\n\r\nWhen I remove the `__precompile__()` before `module test_mysql` and `using test_mysql`, no error was raised and both `ms_df1` and `ms_df2` have valid values as expected, which means `db_conn` was a valid connection when used by both `ms_df1` and `ms_df2`."},"comment":{"url":"https://api.github.com/repos/JuliaDB/MySQL.jl/issues/comments/246902869","html_url":"https://github.com/JuliaDB/MySQL.jl/issues/60#issuecomment-246902869","issue_url":"https://api.github.com/repos/JuliaDB/MySQL.jl/issues/60","id":246902869,"user":{"login":"nkottary","id":2999399,"avatar_url":"https://avatars.githubusercontent.com/u/2999399?v=3","gravatar_id":"","url":"https://api.github.com/users/nkottary","html_url":"https://github.com/nkottary","followers_url":"https://api.github.com/users/nkottary/followers","following_url":"https://api.github.com/users/nkottary/following{/other_user}","gists_url":"https://api.github.com/users/nkottary/gists{/gist_id}","starred_url":"https://api.github.com/users/nkottary/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nkottary/subscriptions","organizations_url":"https://api.github.com/users/nkottary/orgs","repos_url":"https://api.github.com/users/nkottary/repos","events_url":"https://api.github.com/users/nkottary/events{/privacy}","received_events_url":"https://api.github.com/users/nkottary/received_events","type":"User","site_admin":false},"created_at":"2016-09-14T04:23:36Z","updated_at":"2016-09-14T04:23:36Z","body":"That is how precompilation works.  The reason you did not see the error on removing `__precompile__()` is because julia recompiled the file as it was changed.  If you run it again you will see the error.  You need to put the connection statement in `__init__`."}}
{"actor":{"display_login":"nkottary"}}