Skip to content

QueryBuilder .find() throws Attribute Error when not used with a model #925

@circulon

Description

@circulon

Describe the bug
When using a plain QueryBuilder the .find(), .find_or_fail() and .find_or_404() will throw an AttributeError
the error is AttributeError: 'NoneType' object has no attribute 'get_primary_key'

To Reproduce

builder = QueryBuilder()
try:
    record = builder.find(100)
    record = builder.find_or_fail(100)
    record = builder.find_or_404(100)
except ModelNotFound as e:
    print("model not found")
``

**Expected behavior**
when using a plainQueryBuilder without a model,  the methods should either:
return the found recod 
or 
 raise a `ModelNotFound` exception if the record is not found 

**Screenshots or code snippets**.
NA

**Desktop (please complete the following information):**
 - OS: MacOS
 - Version 12.7

**What database are you using?**
 - Type:  all
 - Version NA
 - Masonite ORM 2.24.0

**Additional context**
NA

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn existing feature is not working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions