Skip to content

fix: correct entity field syntax in README code example#32

Open
ElizioMartins wants to merge 1 commit into
objectbox:mainfrom
ElizioMartins:fix/readme-entity-syntax
Open

fix: correct entity field syntax in README code example#32
ElizioMartins wants to merge 1 commit into
objectbox:mainfrom
ElizioMartins:fix/readme-entity-syntax

Conversation

@ElizioMartins
Copy link
Copy Markdown

@ElizioMartins ElizioMartins commented May 20, 2026

Problem

The CRUD code example in README.md uses Id and String as class attributes without parentheses:

@Entity()
class Person:
    id = Id      # ❌ wrong
    name = String  # ❌ wrong

When a user copies this code and tries to instantiate Person(name="Joe Green"), they get a TypeError at runtime because Id and String are descriptor classes that must be instantiated (called with ()) to work correctly as field definitions.

This was originally reported in issue #10 back in 2021 and has been confirmed by multiple users since then.

Fix

Added the missing parentheses to both field definitions:

@Entity()
class Person:
    id = Id()       # ✅ correct
    name = String() # ✅ correct

This matches the syntax used throughout the actual example code in the repository.

Fixes #10


About the contributor: I'm a developer passionate about open source and always looking for opportunities to contribute and grow. If you're looking for collaborators or have open positions, feel free to reach out!

Fields Id and String require parentheses when used as class attributes.
Without `Id()` and `String()`, instantiating the entity with keyword
arguments raises a TypeError at runtime.

Fixes objectbox#10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problem with example in README

1 participant