[BUG]:Synchronised tag fields are not saving #257

Closed
opened 2025-05-13 09:06:29 +00:00 by rsevs3 · 1 comment
rsevs3 commented 2025-05-13 09:06:29 +00:00 (Migrated from github.com)

tag_me/models.py line :534

    def save(
        self,
        name: str = "default",
        sync_tags_save: bool = False,
        *args,
        **kwargs,
    ):
        """
        Saves the model instance and optionally synchronises related tags.

        This method allows you to control whether related tags from synchronised
        content types will also be updated when the model saves.
        :param name: The name of the syncronisation key to use.
                                Defaults to default
        :param sync_tags_save: If True, tags on related content types configured
                               for synchronisation will be updated.  Defaults to False.
        :param args: Additional positional arguments passed to the superclass's save method.
        :param kwargs: Additional keyword arguments passed to the superclass's save method.

        """
        # We don't need to gather synchronising information if the save is
        # for synchronising tags.  The information has already been collected
        if not sync_tags_save:
            print("111111111")
            sync, _ = TagMeSynchronise.objects.get_or_create(
                name=name,
            )
            # Check if tags should be synced for a specific field
            if self.field_name in sync.synchronise.keys():
                print("222222222222")
                # Get other objects with this tag ( then exclude the current one)
                content_ids = copy.deepcopy(
                    sync.synchronise[self.field_name],
                )
                content_ids.remove(
                    self.tagged_field.content_id,
                )

                for content_id in content_ids:
                    print(ContentType.objects.get(id=content_id).model_class().__name__)
                    tagged_field_model = TaggedFieldModel.objects.get(
                        content=content_id,
                        model_name=ContentType.objects.get(id=content_id)
                        .model_class()
                        .__name__,
                        field_name=self.field_name,
                    )

                    instance = UserTag.objects.get(
                        user=self.user,
                        tagged_field=tagged_field_model,
                    )

                    instance.tags = self.tags
                    instance.save(
                        sync_tags_save=True,
                    )

        super().save(*args, **kwargs)

It seems like non synced fields do not use the same logic to pull the database field.

This fixes the issue, but is not necessarily the best fix... Adding the .lower()

                for content_id in content_ids:
                    print(ContentType.objects.get(id=content_id).model_class().__name__)
                    tagged_field_model = TaggedFieldModel.objects.get(
                        content=content_id,
                        model_name=ContentType.objects.get(id=content_id)
                        .model_class()
                        .__name__.lower(),
                        field_name=self.field_name,
                    )
tag_me/models.py line :534 ``` def save( self, name: str = "default", sync_tags_save: bool = False, *args, **kwargs, ): """ Saves the model instance and optionally synchronises related tags. This method allows you to control whether related tags from synchronised content types will also be updated when the model saves. :param name: The name of the syncronisation key to use. Defaults to default :param sync_tags_save: If True, tags on related content types configured for synchronisation will be updated. Defaults to False. :param args: Additional positional arguments passed to the superclass's save method. :param kwargs: Additional keyword arguments passed to the superclass's save method. """ # We don't need to gather synchronising information if the save is # for synchronising tags. The information has already been collected if not sync_tags_save: print("111111111") sync, _ = TagMeSynchronise.objects.get_or_create( name=name, ) # Check if tags should be synced for a specific field if self.field_name in sync.synchronise.keys(): print("222222222222") # Get other objects with this tag ( then exclude the current one) content_ids = copy.deepcopy( sync.synchronise[self.field_name], ) content_ids.remove( self.tagged_field.content_id, ) for content_id in content_ids: print(ContentType.objects.get(id=content_id).model_class().__name__) tagged_field_model = TaggedFieldModel.objects.get( content=content_id, model_name=ContentType.objects.get(id=content_id) .model_class() .__name__, field_name=self.field_name, ) instance = UserTag.objects.get( user=self.user, tagged_field=tagged_field_model, ) instance.tags = self.tags instance.save( sync_tags_save=True, ) super().save(*args, **kwargs) ``` It seems like non synced fields do not use the same logic to pull the database field. This fixes the issue, but is not necessarily the best fix... Adding the .lower() ``` for content_id in content_ids: print(ContentType.objects.get(id=content_id).model_class().__name__) tagged_field_model = TaggedFieldModel.objects.get( content=content_id, model_name=ContentType.objects.get(id=content_id) .model_class() .__name__.lower(), field_name=self.field_name, ) ```
imAsparky commented 2025-05-14 00:56:27 +00:00 (Migrated from github.com)

@rsevs3 thanks for the report and solution.

@rsevs3 thanks for the report and solution.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dunwright/django-tag-me#257
No description provided.