BeanieODM / beanie

Asynchronous Python ODM for MongoDB
http://beanie-odm.dev/
Apache License 2.0
1.94k stars 203 forks source link

[BUG] BackLink error when keep_nulls is set to False #783

Closed Ky73 closed 7 months ago

Ky73 commented 8 months ago

Describe the bug BackLinks results in a value error when keep_nulls is set to False. Specifically fails at this line of code: return {key: self.encode(value) for key, value in obj.items()}.

To Reproduce

  class House(Document, extra="allow"):
      name: str
      door: Link["Door"]
      class Settings:
          name = "house"
          keep_nulls = False
  class Door(Document, extra="allow"):
      height: int = 2
      width: Optional[int] = None
      house: BackLink[House] = Field(original_field="door")
      class Settings:
          name = "Door"
          keep_nulls=False

  async def init():
      client = get_beanie_client()
      await init_beanie(database=client.test_beanie, document_models=[House,Door])
      house = House(name = "NEW NAME1", door = Door())
      await house.insert(link_rule=WriteRules.WRITE)

Expected behavior No error thrown.

Additional context Setting keep_nulls to True does not result in an error.

github-actions[bot] commented 7 months ago

This issue is stale because it has been open 30 days with no activity.

github-actions[bot] commented 7 months ago

This issue was closed because it has been stalled for 14 days with no activity.

kptriescoding commented 1 month ago

I am facing the same issue. Any reason why this is happening?