question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

StopAsyncIteration Exception

See original GitHub issue

Hello, when I execute the following example I get an StopAsyncIteration Exception with no Exception Message.

from pydbantic import Database

class Department(DataBaseModel):
    id: str = PrimaryKey()
    name: str
    company: str
    is_sensitive: bool = False

db = await Database.create('sqlite:///test.db',tables=[Department])

Traceback:

StopAsyncIteration                        Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_19192/144563389.py in <module>
      7     is_sensitive: bool = False
      8 
----> 9 db = await Database.create('sqlite:///test.db',tables=[Department])

~\Documents\.venv\lib\site-packages\pydbantic\database.py in create(cls, DB_URL, tables, cache_enabled, redis_url, logger, debug, testing)
    492 
    493         async with new_db:
--> 494             await new_db.compare_tables_and_migrate()
    495 
    496         return new_db

~\Documents\.venv\lib\site-packages\pydbantic\database.py in compare_tables_and_migrate(self)
    161 
    162         # checkout database for migrations
--> 163         database_init = await DatabaseInit.get(database_url=self.DB_URL)
    164 
    165         if not database_init:

~\Documents\.venv\lib\site-packages\pydbantic\core.py in get(cls, **p_key)
    626             if k != cls.__metadata__.tables[cls.__name__]['primary_key']:
    627                 raise f"Expected primary key {primary_key}=<value>"
--> 628         result = await cls.select('*', where={**p_key})
    629         return result[0] if result else None
    630 

~\Documents\.venv\lib\site-packages\pydbantic\core.py in select(cls, where, alias, limit, offset, *selection)
    431         database = cls.__metadata__.database
    432 
--> 433         results = await database.fetch(sel, cls.__name__, values)
    434 
    435         for result in cls.normalize(results):

~\Documents\.venv\lib\site-packages\pydbantic\database.py in fetch(self, query, table_name, values)
    459         self.log.debug(f"running query: {query} with {values}")
    460 
--> 461         async with self as conn:
    462             row = await conn.fetch_all(query=query)
    463 

~\Documents\.venv\lib\site-packages\pydbantic\database.py in __aenter__(self)
    509                 continue
    510             self.connection_map[conn_id]['last'] = time.time()
--> 511             return await self.connection_map[conn_id]['conn'].asend(None)
    512 
    513         conn_id = str(uuid.uuid4())

StopAsyncIteration: 

Versions

  • Python version 3.9.6
  • Pydbantic version 0.0.15
  • Operating system Windows 10

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Phil997commented, Dec 3, 2021

Ah ok, thanks for your time.

0reactions
codemationcommented, Dec 2, 2021

That is normal, whenever db.create() is called, a lock is placed on the DB for migrations, so no other connected applications try to migrate a DB simultaneously. The message indicates the DB init ( migration and table setup) has completed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Not raising StopAsyncIteration exception in debugger #541
When "Raised Exceptions" is checked the exception StopAsyncIteration gets raised everytime when the async for loop ends.
Read more >
Built-in Exceptions — Python 3.11.1 documentation
In Python, all exceptions must be instances of a class that derives from BaseException. In a try statement with an except clause that...
Read more >
How to get next itereration of async generator after calling ...
To determine if the async generator was cancelled, just try/except on a asyncio.CancelledError exception (which derives from BaseException ).
Read more >
Change history for Faust 1.0 — Faust 1.9.0 documentation
The Python async iterator protocol mandates that it's illegal to raise StopAsyncIteration in an __aiter__ method. Before this change, code such as this:...
Read more >
PyStopAsyncIteration in pyo3::exceptions - Rust
Represents Python's StopAsyncIteration exception. Example: Raising StopAsyncIteration from Rust. This exception can be sent to Python code by converting it into ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found