We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Wrong PositionId on imported Orders
When importing multiple OrderPositions into a single Order, the resulting OrderPositions will all have the same positionid `1`.
Wrong PositionId on imported Orders
When importing multiple OrderPositions into a single Order, the resulting OrderPositions will all have the same positionid `1`.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/pretix/base/services/orderimport.py`
Content:
```
1 import csv
2 import io
3 from decimal import Decimal
4 
5 from django.core.exceptions import ValidationError
6 from django.db import transaction
7 from django.utils.timezone import now
8 from django.utils.translation import gettext as _
9 
10 from pretix.base.i18n import LazyLocaleException, language
11 from pretix.base.models import (
12     CachedFile, Event, InvoiceAddress, Order, OrderPayment, OrderPosition,
13     User,
14 )
15 from pretix.base.orderimport import get_all_columns
16 from pretix.base.services.invoices import generate_invoice, invoice_qualified
17 from pretix.base.services.tasks import ProfiledEventTask
18 from pretix.base.signals import order_paid, order_placed
19 from pretix.celery_app import app
20 
21 
22 class DataImportError(LazyLocaleException):
23     def __init__(self, *args):
24         msg = args[0]
25         msgargs = args[1] if len(args) > 1 else None
26         self.args = args
27         if msgargs:
28             msg = _(msg) % msgargs
29         else:
30             msg = _(msg)
31         super().__init__(msg)
32 
33 
34 def parse_csv(file, length=None):
35     data = file.read(length)
36     try:
37         import chardet
38         charset = chardet.detect(data)['encoding']
39     except ImportError:
40         charset = file.charset
41     data = data.decode(charset or 'utf-8')
42     # If the file was modified on a Mac, it only contains \r as line breaks
43     if '\r' in data and '\n' not in data:
44         data = data.replace('\r', '\n')
45 
46     try:
47         dialect = csv.Sniffer().sniff(data.split("\n")[0], delimiters=";,.#:")
48     except csv.Error:
49         return None
50 
51     if dialect is None:
52         return None
53 
54     reader = csv.DictReader(io.StringIO(data), dialect=dialect)
55     return reader
56 
57 
58 def setif(record, obj, attr, setting):
59     if setting.startswith('csv:'):
60         setattr(obj, attr, record[setting[4:]] or '')
61 
62 
63 @app.task(base=ProfiledEventTask, throws=(DataImportError,))
64 def import_orders(event: Event, fileid: str, settings: dict, locale: str, user) -> None:
65     # TODO: quotacheck?
66     cf = CachedFile.objects.get(id=fileid)
67     user = User.objects.get(pk=user)
68     with language(locale):
69         cols = get_all_columns(event)
70         parsed = parse_csv(cf.file)
71         orders = []
72         order = None
73         data = []
74 
75         # Run validation
76         for i, record in enumerate(parsed):
77             values = {}
78             for c in cols:
79                 val = c.resolve(settings, record)
80                 try:
81                     values[c.identifier] = c.clean(val, values)
82                 except ValidationError as e:
83                     raise DataImportError(
84                         _(
85                             'Error while importing value "{value}" for column "{column}" in line "{line}": {message}').format(
86                             value=val if val is not None else '', column=c.verbose_name, line=i + 1, message=e.message
87                         )
88                     )
89             data.append(values)
90 
91         # Prepare model objects. Yes, this might consume lots of RAM, but allows us to make the actual SQL transaction
92         # shorter. We'll see what works better in reality…
93         for i, record in enumerate(data):
94             try:
95                 if order is None or settings['orders'] == 'many':
96                     order = Order(
97                         event=event,
98                         testmode=settings['testmode'],
99                     )
100                     order.meta_info = {}
101                     order._positions = []
102                     order._address = InvoiceAddress()
103                     order._address.name_parts = {'_scheme': event.settings.name_scheme}
104                     orders.append(order)
105 
106                 position = OrderPosition()
107                 position.attendee_name_parts = {'_scheme': event.settings.name_scheme}
108                 position.meta_info = {}
109                 order._positions.append(position)
110                 position.assign_pseudonymization_id()
111 
112                 for c in cols:
113                     c.assign(record.get(c.identifier), order, position, order._address)
114 
115             except ImportError as e:
116                 raise ImportError(
117                     _('Invalid data in row {row}: {message}').format(row=i, message=str(e))
118                 )
119 
120         # quota check?
121         with event.lock():
122             with transaction.atomic():
123                 for o in orders:
124                     o.total = sum([c.price for c in o._positions])  # currently no support for fees
125                     if o.total == Decimal('0.00'):
126                         o.status = Order.STATUS_PAID
127                         o.save()
128                         OrderPayment.objects.create(
129                             local_id=1,
130                             order=o,
131                             amount=Decimal('0.00'),
132                             provider='free',
133                             info='{}',
134                             payment_date=now(),
135                             state=OrderPayment.PAYMENT_STATE_CONFIRMED
136                         )
137                     elif settings['status'] == 'paid':
138                         o.status = Order.STATUS_PAID
139                         o.save()
140                         OrderPayment.objects.create(
141                             local_id=1,
142                             order=o,
143                             amount=o.total,
144                             provider='manual',
145                             info='{}',
146                             payment_date=now(),
147                             state=OrderPayment.PAYMENT_STATE_CONFIRMED
148                         )
149                     else:
150                         o.status = Order.STATUS_PENDING
151                         o.save()
152                     for p in o._positions:
153                         p.order = o
154                         p.save()
155                     o._address.order = o
156                     o._address.save()
157                     for c in cols:
158                         c.save(o)
159                     o.log_action(
160                         'pretix.event.order.placed',
161                         user=user,
162                         data={'source': 'import'}
163                     )
164 
165             for o in orders:
166                 with language(o.locale):
167                     order_placed.send(event, order=o)
168                     if o.status == Order.STATUS_PAID:
169                         order_paid.send(event, order=o)
170 
171                     gen_invoice = invoice_qualified(o) and (
172                         (event.settings.get('invoice_generate') == 'True') or
173                         (event.settings.get('invoice_generate') == 'paid' and o.status == Order.STATUS_PAID)
174                     ) and not o.invoices.last()
175                     if gen_invoice:
176                         generate_invoice(o, trigger_pdf=True)
177     cf.delete()
178
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/pretix/base/services/orderimport.py b/src/pretix/base/services/orderimport.py
--- a/src/pretix/base/services/orderimport.py
+++ b/src/pretix/base/services/orderimport.py
@@ -103,7 +103,7 @@
                     order._address.name_parts = {'_scheme': event.settings.name_scheme}
                     orders.append(order)
 
-                position = OrderPosition()
+                position = OrderPosition(positionid=len(order._positions) + 1)
                 position.attendee_name_parts = {'_scheme': event.settings.name_scheme}
                 position.meta_info = {}
                 order._positions.append(position)

{"golden_diff": "diff --git a/src/pretix/base/services/orderimport.py b/src/pretix/base/services/orderimport.py\n--- a/src/pretix/base/services/orderimport.py\n+++ b/src/pretix/base/services/orderimport.py\n@@ -103,7 +103,7 @@\n                     order._address.name_parts = {'_scheme': event.settings.name_scheme}\n                     orders.append(order)\n \n-                position = OrderPosition()\n+                position = OrderPosition(positionid=len(order._positions) + 1)\n                 position.attendee_name_parts = {'_scheme': event.settings.name_scheme}\n                 position.meta_info = {}\n                 order._positions.append(position)\n", "issue": "Wrong PositionId on imported Orders\nWhen importing multiple OrderPositions into a single Order, the resulting OrderPositions will all have the same positionid `1`.\nWrong PositionId on imported Orders\nWhen importing multiple OrderPositions into a single Order, the resulting OrderPositions will all have the same positionid `1`.\n", "before_files": [{"content": "import csv\nimport io\nfrom decimal import Decimal\n\nfrom django.core.exceptions import ValidationError\nfrom django.db import transaction\nfrom django.utils.timezone import now\nfrom django.utils.translation import gettext as _\n\nfrom pretix.base.i18n import LazyLocaleException, language\nfrom pretix.base.models import (\n    CachedFile, Event, InvoiceAddress, Order, OrderPayment, OrderPosition,\n    User,\n)\nfrom pretix.base.orderimport import get_all_columns\nfrom pretix.base.services.invoices import generate_invoice, invoice_qualified\nfrom pretix.base.services.tasks import ProfiledEventTask\nfrom pretix.base.signals import order_paid, order_placed\nfrom pretix.celery_app import app\n\n\nclass DataImportError(LazyLocaleException):\n    def __init__(self, *args):\n        msg = args[0]\n        msgargs = args[1] if len(args) > 1 else None\n        self.args = args\n        if msgargs:\n            msg = _(msg) % msgargs\n        else:\n            msg = _(msg)\n        super().__init__(msg)\n\n\ndef parse_csv(file, length=None):\n    data = file.read(length)\n    try:\n        import chardet\n        charset = chardet.detect(data)['encoding']\n    except ImportError:\n        charset = file.charset\n    data = data.decode(charset or 'utf-8')\n    # If the file was modified on a Mac, it only contains \\r as line breaks\n    if '\\r' in data and '\\n' not in data:\n        data = data.replace('\\r', '\\n')\n\n    try:\n        dialect = csv.Sniffer().sniff(data.split(\"\\n\")[0], delimiters=\";,.#:\")\n    except csv.Error:\n        return None\n\n    if dialect is None:\n        return None\n\n    reader = csv.DictReader(io.StringIO(data), dialect=dialect)\n    return reader\n\n\ndef setif(record, obj, attr, setting):\n    if setting.startswith('csv:'):\n        setattr(obj, attr, record[setting[4:]] or '')\n\n\n@app.task(base=ProfiledEventTask, throws=(DataImportError,))\ndef import_orders(event: Event, fileid: str, settings: dict, locale: str, user) -> None:\n    # TODO: quotacheck?\n    cf = CachedFile.objects.get(id=fileid)\n    user = User.objects.get(pk=user)\n    with language(locale):\n        cols = get_all_columns(event)\n        parsed = parse_csv(cf.file)\n        orders = []\n        order = None\n        data = []\n\n        # Run validation\n        for i, record in enumerate(parsed):\n            values = {}\n            for c in cols:\n                val = c.resolve(settings, record)\n                try:\n                    values[c.identifier] = c.clean(val, values)\n                except ValidationError as e:\n                    raise DataImportError(\n                        _(\n                            'Error while importing value \"{value}\" for column \"{column}\" in line \"{line}\": {message}').format(\n                            value=val if val is not None else '', column=c.verbose_name, line=i + 1, message=e.message\n                        )\n                    )\n            data.append(values)\n\n        # Prepare model objects. Yes, this might consume lots of RAM, but allows us to make the actual SQL transaction\n        # shorter. We'll see what works better in reality\u2026\n        for i, record in enumerate(data):\n            try:\n                if order is None or settings['orders'] == 'many':\n                    order = Order(\n                        event=event,\n                        testmode=settings['testmode'],\n                    )\n                    order.meta_info = {}\n                    order._positions = []\n                    order._address = InvoiceAddress()\n                    order._address.name_parts = {'_scheme': event.settings.name_scheme}\n                    orders.append(order)\n\n                position = OrderPosition()\n                position.attendee_name_parts = {'_scheme': event.settings.name_scheme}\n                position.meta_info = {}\n                order._positions.append(position)\n                position.assign_pseudonymization_id()\n\n                for c in cols:\n                    c.assign(record.get(c.identifier), order, position, order._address)\n\n            except ImportError as e:\n                raise ImportError(\n                    _('Invalid data in row {row}: {message}').format(row=i, message=str(e))\n                )\n\n        # quota check?\n        with event.lock():\n            with transaction.atomic():\n                for o in orders:\n                    o.total = sum([c.price for c in o._positions])  # currently no support for fees\n                    if o.total == Decimal('0.00'):\n                        o.status = Order.STATUS_PAID\n                        o.save()\n                        OrderPayment.objects.create(\n                            local_id=1,\n                            order=o,\n                            amount=Decimal('0.00'),\n                            provider='free',\n                            info='{}',\n                            payment_date=now(),\n                            state=OrderPayment.PAYMENT_STATE_CONFIRMED\n                        )\n                    elif settings['status'] == 'paid':\n                        o.status = Order.STATUS_PAID\n                        o.save()\n                        OrderPayment.objects.create(\n                            local_id=1,\n                            order=o,\n                            amount=o.total,\n                            provider='manual',\n                            info='{}',\n                            payment_date=now(),\n                            state=OrderPayment.PAYMENT_STATE_CONFIRMED\n                        )\n                    else:\n                        o.status = Order.STATUS_PENDING\n                        o.save()\n                    for p in o._positions:\n                        p.order = o\n                        p.save()\n                    o._address.order = o\n                    o._address.save()\n                    for c in cols:\n                        c.save(o)\n                    o.log_action(\n                        'pretix.event.order.placed',\n                        user=user,\n                        data={'source': 'import'}\n                    )\n\n            for o in orders:\n                with language(o.locale):\n                    order_placed.send(event, order=o)\n                    if o.status == Order.STATUS_PAID:\n                        order_paid.send(event, order=o)\n\n                    gen_invoice = invoice_qualified(o) and (\n                        (event.settings.get('invoice_generate') == 'True') or\n                        (event.settings.get('invoice_generate') == 'paid' and o.status == Order.STATUS_PAID)\n                    ) and not o.invoices.last()\n                    if gen_invoice:\n                        generate_invoice(o, trigger_pdf=True)\n    cf.delete()\n", "path": "src/pretix/base/services/orderimport.py"}], "after_files": [{"content": "import csv\nimport io\nfrom decimal import Decimal\n\nfrom django.core.exceptions import ValidationError\nfrom django.db import transaction\nfrom django.utils.timezone import now\nfrom django.utils.translation import gettext as _\n\nfrom pretix.base.i18n import LazyLocaleException, language\nfrom pretix.base.models import (\n    CachedFile, Event, InvoiceAddress, Order, OrderPayment, OrderPosition,\n    User,\n)\nfrom pretix.base.orderimport import get_all_columns\nfrom pretix.base.services.invoices import generate_invoice, invoice_qualified\nfrom pretix.base.services.tasks import ProfiledEventTask\nfrom pretix.base.signals import order_paid, order_placed\nfrom pretix.celery_app import app\n\n\nclass DataImportError(LazyLocaleException):\n    def __init__(self, *args):\n        msg = args[0]\n        msgargs = args[1] if len(args) > 1 else None\n        self.args = args\n        if msgargs:\n            msg = _(msg) % msgargs\n        else:\n            msg = _(msg)\n        super().__init__(msg)\n\n\ndef parse_csv(file, length=None):\n    data = file.read(length)\n    try:\n        import chardet\n        charset = chardet.detect(data)['encoding']\n    except ImportError:\n        charset = file.charset\n    data = data.decode(charset or 'utf-8')\n    # If the file was modified on a Mac, it only contains \\r as line breaks\n    if '\\r' in data and '\\n' not in data:\n        data = data.replace('\\r', '\\n')\n\n    try:\n        dialect = csv.Sniffer().sniff(data.split(\"\\n\")[0], delimiters=\";,.#:\")\n    except csv.Error:\n        return None\n\n    if dialect is None:\n        return None\n\n    reader = csv.DictReader(io.StringIO(data), dialect=dialect)\n    return reader\n\n\ndef setif(record, obj, attr, setting):\n    if setting.startswith('csv:'):\n        setattr(obj, attr, record[setting[4:]] or '')\n\n\n@app.task(base=ProfiledEventTask, throws=(DataImportError,))\ndef import_orders(event: Event, fileid: str, settings: dict, locale: str, user) -> None:\n    # TODO: quotacheck?\n    cf = CachedFile.objects.get(id=fileid)\n    user = User.objects.get(pk=user)\n    with language(locale):\n        cols = get_all_columns(event)\n        parsed = parse_csv(cf.file)\n        orders = []\n        order = None\n        data = []\n\n        # Run validation\n        for i, record in enumerate(parsed):\n            values = {}\n            for c in cols:\n                val = c.resolve(settings, record)\n                try:\n                    values[c.identifier] = c.clean(val, values)\n                except ValidationError as e:\n                    raise DataImportError(\n                        _(\n                            'Error while importing value \"{value}\" for column \"{column}\" in line \"{line}\": {message}').format(\n                            value=val if val is not None else '', column=c.verbose_name, line=i + 1, message=e.message\n                        )\n                    )\n            data.append(values)\n\n        # Prepare model objects. Yes, this might consume lots of RAM, but allows us to make the actual SQL transaction\n        # shorter. We'll see what works better in reality\u2026\n        for i, record in enumerate(data):\n            try:\n                if order is None or settings['orders'] == 'many':\n                    order = Order(\n                        event=event,\n                        testmode=settings['testmode'],\n                    )\n                    order.meta_info = {}\n                    order._positions = []\n                    order._address = InvoiceAddress()\n                    order._address.name_parts = {'_scheme': event.settings.name_scheme}\n                    orders.append(order)\n\n                position = OrderPosition(positionid=len(order._positions) + 1)\n                position.attendee_name_parts = {'_scheme': event.settings.name_scheme}\n                position.meta_info = {}\n                order._positions.append(position)\n                position.assign_pseudonymization_id()\n\n                for c in cols:\n                    c.assign(record.get(c.identifier), order, position, order._address)\n\n            except ImportError as e:\n                raise ImportError(\n                    _('Invalid data in row {row}: {message}').format(row=i, message=str(e))\n                )\n\n        # quota check?\n        with event.lock():\n            with transaction.atomic():\n                for o in orders:\n                    o.total = sum([c.price for c in o._positions])  # currently no support for fees\n                    if o.total == Decimal('0.00'):\n                        o.status = Order.STATUS_PAID\n                        o.save()\n                        OrderPayment.objects.create(\n                            local_id=1,\n                            order=o,\n                            amount=Decimal('0.00'),\n                            provider='free',\n                            info='{}',\n                            payment_date=now(),\n                            state=OrderPayment.PAYMENT_STATE_CONFIRMED\n                        )\n                    elif settings['status'] == 'paid':\n                        o.status = Order.STATUS_PAID\n                        o.save()\n                        OrderPayment.objects.create(\n                            local_id=1,\n                            order=o,\n                            amount=o.total,\n                            provider='manual',\n                            info='{}',\n                            payment_date=now(),\n                            state=OrderPayment.PAYMENT_STATE_CONFIRMED\n                        )\n                    else:\n                        o.status = Order.STATUS_PENDING\n                        o.save()\n                    for p in o._positions:\n                        p.order = o\n                        p.save()\n                    o._address.order = o\n                    o._address.save()\n                    for c in cols:\n                        c.save(o)\n                    o.log_action(\n                        'pretix.event.order.placed',\n                        user=user,\n                        data={'source': 'import'}\n                    )\n\n            for o in orders:\n                with language(o.locale):\n                    order_placed.send(event, order=o)\n                    if o.status == Order.STATUS_PAID:\n                        order_paid.send(event, order=o)\n\n                    gen_invoice = invoice_qualified(o) and (\n                        (event.settings.get('invoice_generate') == 'True') or\n                        (event.settings.get('invoice_generate') == 'paid' and o.status == Order.STATUS_PAID)\n                    ) and not o.invoices.last()\n                    if gen_invoice:\n                        generate_invoice(o, trigger_pdf=True)\n    cf.delete()\n", "path": "src/pretix/base/services/orderimport.py"}]}