-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
-
None
-
Python Drivers
-
Not Needed
-
None
-
None
-
None
-
None
-
None
-
None
- Django==5.1.6
- django-mongodb-backend==5.1.0b
from django.db import models from django_mongodb_backend.fields import ArrayField, EmbeddedModelField from django_mongodb_backend.models import EmbeddedModel class Skill(EmbeddedModel): skills = ArrayField(models.CharField(max_length=100), null=True, blank=True) class MyModel(models.Model): name = models.CharField(max_length=20) skills = EmbeddedModelField(Skill) def __str__(self): return f"{self.id}"
This is how I populated the fields:
>>> from app.models import MyModel, Skill >>> a = MyModel() >>> a.name = "raghav" >>> s = Skill() >>> s.skills = ["python", "djnago", "html"] >>> a.skills = s >>> a.save() >>> a <MyModel: 68031a51f94dfbc27a06a715> >>> b = MyModel() >>> b.name = "madhav" >>> r = Skill() >>> r.skills = ["css", "js", "java", "python"] >>> b.skills = r >>> b.save() >>> MyModel.objects.all() <QuerySet [<MyModel: 68031a51f94dfbc27a06a715>, <MyModel: 68031a9df94dfbc27a06a716>]>
>>> MyModel.objects.filter(skills_skills_contains=["python"]) Traceback (most recent call last): File "<console>", line 1, in <module> File "C:\Users\atrey\.conda\envs\django_env\Lib\site-packages\django\db\models\query.py", line 376, in __repr__ data = list(self[: REPR_OUTPUT_SIZE + 1]) File "C:\Users\atrey\.conda\envs\django_env\Lib\site-packages\django\db\models\query.py", line 400, in __iter__ self._fetch_all() ~~~~~~~~~~~~~~~^^ File "C:\Users\atrey\.conda\envs\django_env\Lib\site-packages\django\db\models\query.py", line 1928, in _fetch_all self._result_cache = list(self._iterable_class(self)) ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\atrey\.conda\envs\django_env\Lib\site-packages\django\db\models\query.py", line 91, in __iter__ results = compiler.execute_sql( chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size ) File "C:\Users\atrey\.conda\envs\django_env\Lib\site-packages\django_mongodb_backend\compiler.py", line 245, in execute_sql query = self.build_query( # Avoid $project (columns=None) if unneeded. ...<2 lines>... else None ) File "C:\Users\atrey\.conda\envs\django_env\Lib\site-packages\django_mongodb_backend\compiler.py", line 386, in build_query expr = where.as_mql(self, self.connection) if where else {} ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\atrey\.conda\envs\django_env\Lib\site-packages\django_mongodb_backend\query.py", line 268, in where_node mql = child.as_mql(compiler, connection) File "C:\Users\atrey\.conda\envs\django_env\Lib\site-packages\django_mongodb_backend\lookups.py", line 16, in builtin_lookup value = process_rhs(self, compiler, connection) File "C:\Users\atrey\.conda\envs\django_env\Lib\site-packages\django_mongodb_backend\query_utils.py", line 40, in process_rhs _, value = node.process_rhs(compiler, connection) ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\atrey\.conda\envs\django_env\Lib\site-packages\django\db\models\lookups.py", line 586, in process_rhs params[0] = self.param_pattern % connection.ops.prep_for_like_query( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ params[0] ^^^^^^^^^ ) ^ File "C:\Users\atrey\.conda\envs\django_env\Lib\site-packages\django_mongodb_backend\operations.py", line 173, in prep_for_like_query return re.escape ~~~~~~~~~^^^ File "C:\Users\atrey\.conda\envs\django_env\Lib\re_init_.py", line 312, in escape pattern = str(pattern, 'latin1') TypeError: decoding to str: need a bytes-like object, list found
I getting this when i am query the db. please help me.
this is my first ticket so please let me know if i made any mistake.
django mongodb backend is new so there are less resources on stackoverflow too.