Skip to content
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

Having trouble with users while listening to tickets being created #21

Open
OtavioZys opened this issue Apr 13, 2023 · 0 comments
Open

Comments

@OtavioZys
Copy link

Getting the error Invalid field name(s) for model ZendeskUser: 'user'. for every ticket.

Here is the full traceback:

`\apps\zengo\views.py, line 39, in post
        if not self.validate_secret():
            return HttpResponseForbidden(strings.secret_missing_or_wrong)
        processor = get_processor()
        try:
            event = processor.store_event(request.body.decode("utf-8"))
        except ValidationError as ve:
            return HttpResponseBadRequest(ve.message)
        processor.begin_processing_event(event) …
        return HttpResponse()

\apps\zengo\service.py, line 360, in begin_processing_event
            raise ValidationError(strings.data_no_ticket_id)
        event.remote_ticket_id = data["id"]
        event.save(update_fields=("remote_ticket_id", "updated_at"))
        return event
    def begin_processing_event(self, event):
        return self.process_event_and_record_errors(event) …
    def process_event_and_record_errors(self, event):
        try:
            # potentially serialize processing per-ticket such that there isn't
            # doubling up on signals firing
            with self.acquire_ticket_lock(event.remote_ticket_id):

\apps\zengo\service.py, line 367, in process_event_and_record_errors
        return self.process_event_and_record_errors(event)
    def process_event_and_record_errors(self, event):
        try:
            # potentially serialize processing per-ticket such that there isn't
            # doubling up on signals firing
            with self.acquire_ticket_lock(event.remote_ticket_id):
                self.process_event(event) …
        except Exception:
            logger.exception(
                "Failed to process Zendesk event",
                extra=dict(
                    event_id=event.id,

\zengo\service.py, line 399, in process_event
        # take a snapshot of the ticket and its comments in their old state
        pre_sync_ticket = models.Ticket.objects.filter(zendesk_id=ticket_id).first()
        pre_sync_comments = []
        if pre_sync_ticket:
            pre_sync_comments = list(pre_sync_ticket.comments.all())
        post_sync_ticket, created = get_service().sync_ticket_id(ticket_id) …
        post_sync_comments = list(post_sync_ticket.comments.all())
        # build update context for passing downstream
        update_context = {
            "pre_ticket": pre_sync_ticket,

\apps\zengo\service.py, line 219, in sync_ticket_id
                # store their latest photo JSON data
                photos_json=json.dumps(remote_zd_user.photo),
            ),
        )
        return instance
    def sync_ticket_id(self, ticket_id):
        return self.sync_ticket(self.client.tickets(id=ticket_id)) …
    def sync_ticket(self, remote_zd_ticket):
        """
        Create or update local representations of a Zendesk ticket, its comments
        and all associated Zendesk users.

\apps\zengo\service.py, line 249, in sync_ticket
            [remote_zd_ticket.requester]
            + [c.author for c in remote_comments if c.author_id != -1]  # noqa
        )
        users = list(users)
        users.sort(key=lambda u: u.id)
        # sync the users and establish a mapping to local records
        user_map = {u: self.sync_user(u) for u in users} …
        defaults = dict(
            requester=user_map[remote_zd_ticket.requester],
            subject=remote_zd_ticket.subject,
            url=remote_zd_ticket.url,
            status=models.Ticket.states.by_id.get(remote_zd_ticket.status.lower()),

\apps\zengo\service.py, line 249, in <dictcomp>
            [remote_zd_ticket.requester]
            + [c.author for c in remote_comments if c.author_id != -1]  # noqa
        )
        users = list(users)
        users.sort(key=lambda u: u.id)
        # sync the users and establish a mapping to local records
        user_map = {u: self.sync_user(u) for u in users} …
        defaults = dict(
            requester=user_map[remote_zd_ticket.requester],
            subject=remote_zd_ticket.subject,
            url=remote_zd_ticket.url,
            status=models.Ticket.states.by_id.get(remote_zd_ticket.status.lower()),

\apps\zengo\service.py, line 201, in sync_user
            remote_zd_user = self.create_remote_zd_user_for_local_user(local_user)
        return remote_zd_user
    def sync_user(self, remote_zd_user):
        """
        Given a RemoteZendeskUser instance, persist it as a local ZendeskUser instance.
        """
        instance, created = models.ZendeskUser.objects.update_or_create( …
            zendesk_id=remote_zd_user.id,
            defaults=dict(
                # attempt to resolve the local user if possible
                user=self.get_local_user_for_external_id(remote_zd_user.external_id),
                alias=remote_zd_user.alias,
                email=remote_zd_user.email,`
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

No branches or pull requests

1 participant