Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

could not retrieve data from model #2

Open
cesarmarinhorj opened this issue Apr 26, 2022 · 1 comment
Open

could not retrieve data from model #2

cesarmarinhorj opened this issue Apr 26, 2022 · 1 comment

Comments

@cesarmarinhorj
Copy link

this is in normal shell:

Python 3.8.5 (default, Nov  9 2020, 09:50:59) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from tubo.models import *
>>> Lote.objects.first()
<Lote: Lote object (385)>
>>> 

this is is ptpython as shell:

>>> from tubo.models import *
>>> l = Lote.objects.first()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/cesar/Desktop/Projetos/Estudos/Python/estudos/web/Django/lib/python3.8/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/cesar/Desktop/Projetos/Estudos/Python/estudos/web/Django/lib/python3.8/site-packages/django/db/models/query.py", line 753, in first
    for obj in (self if self.ordered else self.order_by("pk"))[:1]:
  File "/home/cesar/Desktop/Projetos/Estudos/Python/estudos/web/Django/lib/python3.8/site-packages/django/db/models/query.py", line 320, in __iter__
    self._fetch_all()
  File "/home/cesar/Desktop/Projetos/Estudos/Python/estudos/web/Django/lib/python3.8/site-packages/django/db/models/query.py", line 1507, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/home/cesar/Desktop/Projetos/Estudos/Python/estudos/web/Django/lib/python3.8/site-packages/django/db/models/query.py", line 57, in __iter__
    results = compiler.execute_sql(
  File "/home/cesar/Desktop/Projetos/Estudos/Python/estudos/web/Django/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1359, in execute_sql
    cursor = self.connection.cursor()
  File "/home/cesar/Desktop/Projetos/Estudos/Python/estudos/web/Django/lib/python3.8/site-packages/django/utils/asyncio.py", line 24, in inner
    raise SynchronousOnlyOperation(message)
django.core.exceptions.SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async.

You cannot call this from an async context - use a thread or sync_to_async.
>>>

why???

thanks!
I love ptpython, weel be great use it with Django.

@reganto
Copy link
Owner

reganto commented Apr 27, 2022

Hi, According to log there seems to be an exception related to django core and your project setup (django.core.exceptions.SynchronousOnlyOperation) and not django-ptpython. I can't regenerate exception unless you provide more information. nonetheless you can give it a try with a simple model and then import particular models instead of importing all objects of the module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants