Revert "Order import: Catch CSV parsing errors during iteration (PRETIXEU-9AW)"

This reverts commit 77ff0298f1.
This commit is contained in:
Raphael Michel
2023-11-10 10:19:05 +01:00
parent 99b5f3cc3b
commit 4708509585

View File

@@ -32,7 +32,6 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under the License. # License for the specific language governing permissions and limitations under the License.
import csv
import logging import logging
from datetime import timedelta from datetime import timedelta
@@ -147,24 +146,16 @@ class ProcessView(EventPermissionRequiredMixin, AsyncAction, FormView):
else: else:
charset = None charset = None
try: try:
try: return parse_csv(self.file.file, 1024 * 1024, charset=charset)
c = parse_csv(self.file.file, 1024 * 1024, charset=charset) except UnicodeDecodeError:
if c is not None: messages.warning(
return list(c) self.request,
except UnicodeDecodeError: _(
messages.warning( "We could not identify the character encoding of the CSV file. "
self.request, "Some characters were replaced with a placeholder."
_(
"We could not identify the character encoding of the CSV file. "
"Some characters were replaced with a placeholder."
)
) )
c = parse_csv(self.file.file, 1024 * 1024, "replace", charset=charset) )
if c is not None: return parse_csv(self.file.file, 1024 * 1024, "replace", charset=charset)
return list(c)
except csv.Error:
logger.exception("Could not parse CSV file")
return None
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
if 'async_id' in request.GET and settings.HAS_CELERY: if 'async_id' in request.GET and settings.HAS_CELERY:
@@ -202,5 +193,5 @@ class ProcessView(EventPermissionRequiredMixin, AsyncAction, FormView):
ctx = super().get_context_data(**kwargs) ctx = super().get_context_data(**kwargs)
ctx['file'] = self.file ctx['file'] = self.file
ctx['parsed'] = self.parsed ctx['parsed'] = self.parsed
ctx['sample_rows'] = self.parsed[:3] ctx['sample_rows'] = list(self.parsed)[:3]
return ctx return ctx