-
Notifications
You must be signed in to change notification settings - Fork 27
Closed
Description
Context
after running python mange.py shell I attempted to query the database I just collected.
>>> from django.utils import timezone
>>> q = Question(question_text="What's new?", pub_date=timezone.now())
>>> q.save()
>>> q.id
ObjectId('66b24df05ad79637c54da774')
>>> q.question_text = "What's up"
>>> q.save()
Traceback (most recent call last):
File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django/db/models/fields/__init__.py", line 2117, in get_prep_value
return int(value)
^^^^^^^^^^
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'ObjectId'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django/db/models/base.py", line 822, in save
self.save_base(
File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django/db/models/base.py", line 909, in save_base
updated = self._save_table(
^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django/db/models/base.py", line 1040, in _save_table
updated = self._do_update(
^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django/db/models/base.py", line 1084, in _do_update
filtered = base_qs.filter(pk=pk_val)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django/db/models/query.py", line 1476, in filter
return self._filter_or_exclude(False, args, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django/db/models/query.py", line 1494, in _filter_or_exclude
clone._filter_or_exclude_inplace(negate, args, kwargs)
File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django/db/models/query.py", line 1501, in _filter_or_exclude_inplace
self._query.add_q(Q(*args, **kwargs))
File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django/db/models/sql/query.py", line 1613, in add_q
clause, _ = self._add_q(q_object, self.used_aliases)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django/db/models/sql/query.py", line 1645, in _add_q
child_clause, needed_inner = self.build_filter(
^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django/db/models/sql/query.py", line 1559, in build_filter
condition = self.build_lookup(lookups, col, value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django/db/models/sql/query.py", line 1389, in build_lookup
lookup = lookup_class(lhs, rhs)
^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django/db/models/lookups.py", line 30, in __init__
self.rhs = self.get_prep_lookup()
^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django/db/models/lookups.py", line 364, in get_prep_lookup
return super().get_prep_lookup()
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django/db/models/lookups.py", line 88, in get_prep_lookup
return self.lhs.output_field.get_prep_value(self.rhs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django/db/models/fields/__init__.py", line 2119, in get_prep_value
raise e.__class__(
TypeError: Field 'id' expected a number but got ObjectId('66b24df05ad79637c54da774').
>>> q.save()
When I check the database I do see the value, and running this yields:
>>> Question.objects.all().values()
<QuerySet [{'id': None, 'question_text': "What's new?", 'pub_date': datetime.datetime(2024, 8, 6, 16, 23, 10, 65000, tzinfo=datetime.timezone.utc)}]>
Metadata
Metadata
Assignees
Labels
No labels