Skip to content

[BUG] Link field query fails when document field named 'title' conflicts with Link's collection name property #1261

Description

@syedhabib39

Describe the bug
When using a field named title in a Beanie document and referencing it through a Link in another document, querying the linked document's title field throws an AttributeError. The error occurs because Beanie appears to be conflicting with Python's built-in str.title() method, returning <built-in method title of ExpressionField object at 0x7e1098dd23d0> instead of the field value. According to the source code, in Link objects, title refers to its collection name, which creates a naming conflict when trying to access a document field also named title.

To Reproduce

from beanie import Document, Link
from typing import Optional

class Subject(Document):
    title: str

class Chapter(Document):
    title: str
    subject: Link[Subject]

# This query fails with AttributeError
data = await Chapter.find(Chapter.subject.title == 'sub1')

# Error: AttributeError: 'builtin_function_or_method' object has no attribute 'split'
# The error suggests that Chapter.subject.title is returning the built-in str.title() method
# instead of the actual field reference

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions