eventyay-tickets icon indicating copy to clipboard operation
eventyay-tickets copied to clipboard

Different events can now have the same ticket ID

Open suhailnadaf509 opened this issue 8 months ago • 5 comments

I've modified the Secret class to only check for duplicate ticket IDs within the same event by changing the query from order__event__organizer=self.event.organizer to order__event=self.event Fixes #575

Summary by Sourcery

Bug Fixes:

  • Fixes an issue where ticket IDs could not be reused across different events by modifying the Secret class to only check for duplicate ticket IDs within the same event.

suhailnadaf509 avatar Mar 14 '25 15:03 suhailnadaf509

Reviewer's Guide by Sourcery

This pull request modifies the Secret class to prevent duplicate ticket IDs within the same event. The query for existing ticket IDs has been updated to filter by event instead of organizer.

Sequence diagram for checking duplicate ticket IDs

sequenceDiagram
    participant User
    participant OrderImport
    participant OrderPosition

    User->>OrderImport: Imports order with ticket ID
    OrderImport->>OrderPosition: Checks if ticket ID exists for the event
    OrderPosition-->>OrderImport: Returns true if ticket ID exists, false otherwise
    alt Ticket ID exists
        OrderImport-->>User: Raises ValidationError
    else Ticket ID does not exist
        OrderImport->>OrderImport: Continues order import
    end

Updated class diagram for OrderPosition

classDiagram
    class OrderPosition {
        -id: int
        -order: Order
        -secret: str
        -event: Event
    }
    class Order {
        -id: int
        -event: Event
    }
    class Event {
        -id: int
        -organizer: Organizer
    }
    class Organizer {
        -id: int
    }
    OrderPosition -- Order : order
    Order -- Event : event
    Event -- Organizer : organizer
    OrderPosition -- Event : event
    note for OrderPosition "The query for existing ticket IDs has been updated to filter by event instead of organizer."

File-Level Changes

Change Details Files
Modified the Secret class to only check for duplicate ticket IDs within the same event.
  • Changed the query to filter OrderPosition objects by event instead of organizer.
  • Updated the filter from order__event__organizer=self.event.organizer to order__event=self.event.
src/pretix/base/orderimport.py

Assessment against linked issues

Issue Objective Addressed Explanation
#575 Allow tickets from different events to have the same ID.

Possibly linked issues

  • #575: The PR fixes the issue by changing the query to check for duplicate ticket IDs within the same event.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an issue from a review comment by replying to it. You can also reply to a review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull request title to generate a title at any time. You can also comment @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment @sourcery-ai summary on the pull request to (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

  • Contact our support team for questions or feedback.
  • Visit our documentation for detailed guides and information.
  • Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.

sourcery-ai[bot] avatar Mar 14 '25 15:03 sourcery-ai[bot]

The fix is necessary because the current implementation incorrectly restricts ticket IDs (secrets) to be unique across all events managed by the same organizer, rather than just within a single event.

suhailnadaf509 avatar Mar 15 '25 08:03 suhailnadaf509

Please don't write "Fix #..." in the title. It should be in PR description.

hongquan avatar Mar 21 '25 08:03 hongquan

@Sak1012 Your are right! , well i think we should change the order model to contain a event-scoped constraint something like this to the OrderPosition model in src/pretix/base/models/orders.py

class Meta:
    verbose_name = _("Order position")
    verbose_name_plural = _("Order positions")
    ordering = ("positionid", "id")
    constraints = [
        # Make secrets unique only within the same event
        models.UniqueConstraint(
            fields=['order__event', 'secret'], 
            name='unique_secret_per_event'
        )
    ]

and then create a migration file for the above made changes

from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('pretixbase', 'previous_migration'),  # I will Replace these with actual dependencies just a placeholder for now
    ]
        migrations.AddConstraint(
            model_name='orderposition',
            constraint=models.UniqueConstraint(fields=['order__event', 'secret'], name='unique_secret_per_event'),
        ),
    ]

then i decided that we should update the the assign_ticket_secret function to make it event-aware i was hoping this updation using random generator might do it

def assign_ticket_secret(event, position, force_invalidate_if_revokation_list_used=False, force_invalidate=False, save=True):

    from pretix.base.models.orders import generate_position_secret
    gen = event.ticket_secret_generator

    if gen.use_revocation_list and force_invalidate_if_revokation_list_used:
        force_invalidate = True

    original_secret = position.secret

    # For the RandomTicketSecretGenerator, we want to use our custom event-aware function
    if gen.identifier == 'random':
        if force_invalidate or not position.secret:
            # Use the event-aware generation
            position.secret = generate_position_secret(event=event)
            changed = original_secret != position.secret
        else:
            # Keep existing secret
            changed = False
    else:
        # For specialized generators like Sig1, use their own methods
        kwargs = {}
        if 'attendee_name' in inspect.signature(gen.generate_secret).parameters:
            kwargs['attendee_name'] = position.attendee_name

        secret = gen.generate_secret(
            item=position.item,
            variation=position.variation,
            subevent=position.subevent,
            current_secret=position.secret,
            force_invalidate=force_invalidate,
            **kwargs
        )
        changed = position.secret != secret
        if position.secret and changed and gen.use_revocation_list:
            position.revoked_secrets.create(event=event, secret=position.secret)
        position.secret = secret

    if save and changed:
        position.save()

suhailnadaf509 avatar Apr 30 '25 06:04 suhailnadaf509

class Meta:
    verbose_name = _("Order position")
    verbose_name_plural = _("Order positions")
    ordering = ("positionid", "id")
    constraints = [
        # Make secrets unique only within the same event
        models.UniqueConstraint(
            fields=['order__event', 'secret'], 
            name='unique_secret_per_event'
        )
    ]

This does not add a global scope. This makes sure that for each Event, no two OrderPosition objects have the same secret, which is already done in a separate function save().

In the changes for assign_ticket_secret some of the imports like

from pretix.base.models.orders import generate_position_secret

will not work as it does not exist.

Sak1012 avatar May 19 '25 15:05 Sak1012

@suhailnadaf509 can you finish the work you started? Thanks

hpdang avatar Jun 04 '25 18:06 hpdang