Create objects and writing queries without any filters works as a charm, but when I'm trying to use simple lambda, smth like
Lecturer.select(lambda l: name_filter in l.name)[:]
I'm get following error
Error
```
File "/Users/vasiaplaton/work/VsevolodSoroka/Dekanat/main.py", line 36, in init_lecturers
for i in db.get_lecturers("Аким"):
^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 2, in get_lecturers
File "/opt/homebrew/lib/python3.11/site-packages/pony/orm/core.py", line 519, in new_func
result = func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/vasiaplaton/work/VsevolodSoroka/Dekanat/db.py", line 51, in get_lecturers
return q.filter(lambda l: name_filter in l.name)[:]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/pony/orm/core.py", line 6114, in filter
return query._process_lambda(func, globals, locals, order_by=False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/pony/orm/core.py", line 6048, in _process_lambda
func_ast, external_names, cells = decompile(func)
^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/pony/orm/decompiling.py", line 38, in decompile
decompiler = Decompiler(codeobject)
^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/pony/orm/decompiling.py", line 154, in __init__
decompiler.get_instructions()
File "/opt/homebrew/lib/python3.11/site-packages/pony/orm/decompiling.py", line 204, in get_instructions
arg = [free[oparg]]
~~~~^^^^^^^
IndexError: tuple index out of range
```
But for example Lecturer.select()[:] works as expected and return right data.
What should I do?
Full code:
Code
```python
from pony.orm import *
db = Database()
class Student(db.Entity):
id = PrimaryKey(int, auto=True)
name = Required(str)
marks = Set('Mark')
group = Required('Group')
class Mark(db.Entity):
id = PrimaryKey(int, auto=True)
mark = Required(str)
student = Required(Student)
subject = Required('Subject')
class Group(db.Entity):
id = PrimaryKey(int, auto=True)
num = Required(int)
course = Required(int)
students = Set(Student)
class Subject(db.Entity):
id = PrimaryKey(int, auto=True)
name = Required(str)
lecturers = Set('Lecturer')
marks = Set(Mark)
class Lecturer(db.Entity):
id = PrimaryKey(int, auto=True)
name = Required(str)
subjects = Set(Subject)
class DekanatDB:
def __init__(self, filename: str):
set_sql_debug(True)
db.bind('sqlite', filename=filename)
db.generate_mapping(check_tables=True)
@db_session
def get_lecturers(self, name_filter=None) -> list[Lecturer]:
if name_filter is None:
return Lecturer.select()[:]
else:
return Lecturer.select(lambda l: name_filter in l.name)[:]
```
Recently installed and trying to use Pony ORM
Create objects and writing queries without any filters works as a charm, but when I'm trying to use simple lambda, smth like
Lecturer.select(lambda l: name_filter in l.name)[:]
I'm get following errorError
``` File "/Users/vasiaplaton/work/VsevolodSoroka/Dekanat/main.py", line 36, in init_lecturers for i in db.get_lecturers("Аким"): ^^^^^^^^^^^^^^^^^^^^^^^^ File "But for example
Lecturer.select()[:]
works as expected and return right data.What should I do?
Full code:
Code
```python from pony.orm import * db = Database() class Student(db.Entity): id = PrimaryKey(int, auto=True) name = Required(str) marks = Set('Mark') group = Required('Group') class Mark(db.Entity): id = PrimaryKey(int, auto=True) mark = Required(str) student = Required(Student) subject = Required('Subject') class Group(db.Entity): id = PrimaryKey(int, auto=True) num = Required(int) course = Required(int) students = Set(Student) class Subject(db.Entity): id = PrimaryKey(int, auto=True) name = Required(str) lecturers = Set('Lecturer') marks = Set(Mark) class Lecturer(db.Entity): id = PrimaryKey(int, auto=True) name = Required(str) subjects = Set(Subject) class DekanatDB: def __init__(self, filename: str): set_sql_debug(True) db.bind('sqlite', filename=filename) db.generate_mapping(check_tables=True) @db_session def get_lecturers(self, name_filter=None) -> list[Lecturer]: if name_filter is None: return Lecturer.select()[:] else: return Lecturer.select(lambda l: name_filter in l.name)[:] ```