title: Using apscheduler with asyncpg db as Job Store: Error MissingGreenlet
body: <p>I'm trying to use Apscheduler with a postgresql db via an asyncpg connection. I thought it would working, because asyncpg supports sqlalchemy <a href="https://magicstack.github.io/asyncpg/current/faq.html#can-i-use-asyncpg-with-sqlalchemy-orm" rel="nofollow noreferrer">ref</a>. But yeah, it isn't working. And to make it even worst, I don't understand the error message, so I have not even a guess what to google for.</p>
  <pre class="lang-py prettyprint-override"><code>import asyncio
  from apscheduler.schedulers.asyncio import AsyncIOScheduler
  from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore
  
  def simple_job():
      print('This was an easy job!')
  
  scheduler = AsyncIOScheduler()
  jobstore = SQLAlchemyJobStore(url='postgresql+asyncpg://user:password@localhost:5432/public')
  scheduler.add_jobstore(jobstore)
  # schedule a simple job
  scheduler.add_job(simple_job, 'cron', second='15', id='heartbeat',
      coalesce=True, misfire_grace_time=5, replace_existing=True)
  scheduler.start()
  </code></pre>
  <p>Versions:</p>
  <pre><code>python 3.7
  APScheduler==3.7.0
  asyncpg==0.22.0
  SQLAlchemy==1.4.3
  </code></pre>
  <p>Error Message and traceback:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;C:/Users/d/PycharmProjects/teamutils/utils/automation.py&quot;, line 320, in &lt;module&gt;
      scheduler.start()
    File &quot;C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\apscheduler\schedulers\asyncio.py&quot;, line 45, in start
      super(AsyncIOScheduler, self).start(paused)
    File &quot;C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\apscheduler\schedulers\base.py&quot;, line 163, in start
      store.start(self, alias)
    File &quot;C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\apscheduler\jobstores\sqlalchemy.py&quot;, line 68, in start
      self.jobs_t.create(self.engine, True)
    File &quot;C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\sql\schema.py&quot;, line 940, in create
      bind._run_ddl_visitor(ddl.SchemaGenerator, self, checkfirst=checkfirst)
    File &quot;C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\engine\base.py&quot;, line 2979, in _run_ddl_visitor
      with self.begin() as conn:
    File &quot;C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\engine\base.py&quot;, line 2895, in begin
      conn = self.connect(close_with_result=close_with_result)
    File &quot;C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\engine\base.py&quot;, line 3067, in connect
      return self._connection_cls(self, close_with_result=close_with_result)
    File &quot;C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\engine\base.py&quot;, line 91, in __init__
      else engine.raw_connection()
    File &quot;C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\engine\base.py&quot;, line 3146, in raw_connection
      return self._wrap_pool_connect(self.pool.connect, _connection)
    File &quot;C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\engine\base.py&quot;, line 3113, in _wrap_pool_connect
      return fn()
    File &quot;C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\pool\base.py&quot;, line 301, in connect
      return _ConnectionFairy._checkout(self)
    File &quot;C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\pool\base.py&quot;, line 755, in _checkout
      fairy = _ConnectionRecord.checkout(pool)
    File &quot;C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\pool\base.py&quot;, line 419, in checkout
      rec = pool._do_get()
    File &quot;C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\pool\impl.py&quot;, line 145, in _do_get
      self._dec_overflow()
    File &quot;C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\util\langhelpers.py&quot;, line 72, in __exit__
      with_traceback=exc_tb,
    File &quot;C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\util\compat.py&quot;, line 198, in raise_
      raise exception
    File &quot;C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\pool\impl.py&quot;, line 142, in _do_get
      return self._create_connection()
    File &quot;C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\pool\base.py&quot;, line 247, in _create_connection
      return _ConnectionRecord(self)
    File &quot;C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\pool\base.py&quot;, line 362, in __init__
      self.__connect(first_connect_check=True)
    File &quot;C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\pool\base.py&quot;, line 605, in __connect
      pool.logger.debug(&quot;Error on connect(): %s&quot;, e)
    File &quot;C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\util\langhelpers.py&quot;, line 72, in __exit__
      with_traceback=exc_tb,
    File &quot;C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\util\compat.py&quot;, line 198, in raise_
      raise exception
    File &quot;C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\pool\base.py&quot;, line 599, in __connect
      connection = pool._invoke_creator(self)
    File &quot;C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\engine\create.py&quot;, line 578, in connect
      return dialect.connect(*cargs, **cparams)
    File &quot;C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\engine\default.py&quot;, line 548, in connect
      return self.dbapi.connect(*cargs, **cparams)
    File &quot;C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\dialects\postgresql\asyncpg.py&quot;, line 744, in connect
      await_only(self.asyncpg.connect(*arg, **kw)),
    File &quot;C:\Users\d\PycharmProjects\teamutils\venv\lib\site-packages\sqlalchemy\util\_concurrency_py3k.py&quot;, line 48, in await_only
      &quot;greenlet_spawn has not been called; can't call await_() here. &quot;
  sqlalchemy.exc.MissingGreenlet: greenlet_spawn has not been called; can't call await_() here. Was IO attempted in an unexpected place? (Background on this error at: http://sqlalche.me/e/14/xd2s)
  sys:1: RuntimeWarning: coroutine 'connect' was never awaited
  </code></pre>
  <p>I looked up the provided link, but not getting smart of it. So it would be nice, if somebody can tell me what is going on, so I can search for a solution by my own. (a solution would okay too, of course xD)</p>
  <p>Sorry for this &quot;open&quot; question, but my understanding is so bad, that I dont know what to ask for.</p>