-
-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Backlinks are not populated #885
Comments
Hi @sheoak , thank you for the issue. I'll check what is going on there and will update you here. It is probably a bug |
Looked at the implementation - In this case the following happens:
So at the moment you have to use |
I'm not quite sure if this is related, but when I try to find documents that have a BackLink I get an error, that the BackLink field can not be encoded Error
Codeimport asyncio
from beanie import init_beanie, Document
from motor.motor_asyncio import AsyncIOMotorClient
from app.models import Summoner, LeagueEntry
async def init():
client = AsyncIOMotorClient(
"mongodb://localhost:27017",
)
await init_beanie(database=client.test_db, document_models=[Summoner, LeagueEntry])
summoner = Summoner(
game_name = "test",
name = "test",
platform = "test",
profile_icon_id = 1,
puuid = "test",
summoner_id = "test",
summoner_level = 1,
tag_line = "test",
)
await summoner.insert()
league_entry = LeagueEntry(
league_id="test",
queue_type="test",
tier="test",
rank="test",
league_points=1,
wins=1,
losses=1,
veteran=False,
inactive=False,
fresh_blood=False,
hot_streak=False,
summoner=summoner,
)
await league_entry.insert()
# get all league entries of the summoner
league_entries = await LeagueEntry.find(LeagueEntry.summoner == summoner).to_list()
print(league_entries)
asyncio.run(init()) Modelsimport pymongo
from pydantic import BaseModel, Field
from beanie import Document, Link, BackLink
# A summoner can have multiple league entries or none at all
# A league entry is linked to a summoner
class Summoner(Document):
game_name: str
name: str
platform: str
profile_icon_id: int
puuid: str
summoner_id: str
summoner_level: int
tag_line: str
league_entries: list[BackLink["LeagueEntry"]] = Field(original_field="summoner")
class Settings:
name = "summoner"
indexes = [
[
("game_name", pymongo.TEXT),
("tag_line", pymongo.TEXT),
("platform", pymongo.TEXT),
]
]
class LeagueEntry(Document):
league_id: str
queue_type: str
tier: str
rank: str
league_points: int
wins: int
losses: int
veteran: bool
inactive: bool
fresh_blood: bool
hot_streak: bool
summoner: Link[Summoner]
class Settings:
name = "league_entry"
indexes = [
[
("tier", pymongo.TEXT),
("rank", pymongo.TEXT),
("league_points", pymongo.TEXT),
]
] |
I don't know if this is related, but in Pydantic v2 it seems like the way to define a class Door(Document):
house: BackLink[House] = Field(json_schema_extra={"original_field": "door"}) as opposed to class Door(Document):
house: BackLink[House] = Field(original_field="door") |
Yes, and the new format is poorly documented. But it still doesn’t work in my case. |
Any updates on this? |
Any updates on this? Is there a way on demand fetch one particular BackLink field? Can someone share an example? |
Yeah, this is causing issues for us as well, the weird part is that it seems to periodically work. Has any work been done on this? |
it also seems that there are a lot of tickets on nested links not populating that have been closed by the bot even though they have not been completed. on the links we can run through the object and force them to populate, but because it isnt really possible to fetch a backlink after the initial search, this becomes quite difficult |
Will this be resolved in the near future ? Beside that it's a lot of try and error to get the magic behind it ... the documentation is kinda minimal when it comes to stuff like that. At the moment the whole code we use isn't even remotely populating something on the list of backlinked documents. |
Describe the bug
When creating backlinks, the documentation (to my knowledge) doesn’t show a way to retrieve them immediately.
This has been asked several times in the questions section, but I realized none of them are answered so I post this as an issue now.
Is there a way to populate the backlink, similar to fetch_all_links with Link objects? (see example below)
To Reproduce
Considering the definitions below:
The following does NOT work:
This works:
Expected behavior
Backlinks should be populated
The text was updated successfully, but these errors were encountered: