Skip to content

use class from self.__class__ when serializing BackLinks with fetched data#1207

Open
alexdlukens wants to merge 1 commit intoBeanieODM:mainfrom
alexdlukens:fix-backlink-return-collection
Open

use class from self.__class__ when serializing BackLinks with fetched data#1207
alexdlukens wants to merge 1 commit intoBeanieODM:mainfrom
alexdlukens:fix-backlink-return-collection

Conversation

@alexdlukens
Copy link

This is my proposed solution for #1189. Please find the minimal code example in the issue report.

This fixes serialization in the case when BackLink data has been fetched using fetch_links=True. In this situation, the BackLink field contains a Document object, which does not have the document_class attribute.

Thanks,

@alexdlukens alexdlukens force-pushed the fix-backlink-return-collection branch from 337d6f7 to 80da15b Compare July 19, 2025 16:10
@alexdlukens alexdlukens changed the title use class from self.__class__ if document_class does not exist when serializing BackLinks use class from self.__class__ when serializing BackLinks with fetched data Jul 19, 2025
@CAPITAINMARVEL
Copy link
Contributor

CAPITAINMARVEL commented Aug 27, 2025

This is my proposed solution for #1189. Please find the minimal code example in the issue report.

This fixes serialization in the case when BackLink data has been fetched using fetch_links=True. In this situation, the BackLink field contains a Document object, which does not have the document_class attribute.

Thanks,

maybe a getattr(self, "document_class", self.class) instead ?

With attribute:
try/except: 0.0754515000153333
getattr: 0.08347969996975735

Without attribute:
try/except: 0.4134541000239551
getattr: 0.08493790001375601

this is what i got with a testing script (using timeit)

This is the case when BackLink data has been fetched using fetch_links=True
@alexdlukens alexdlukens force-pushed the fix-backlink-return-collection branch from 80da15b to 2685fae Compare August 28, 2025 03:51
@CAPITAINMARVEL CAPITAINMARVEL requested a review from a team August 28, 2025 09:17
@github-actions
Copy link
Contributor

This PR is stale because it has been open 45 days with no activity.

@github-actions
Copy link
Contributor

This PR is stale because it has been open 45 days with no activity.

@github-actions
Copy link
Contributor

This PR is stale because it has been open 45 days with no activity.

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.

3 participants