Opened 8 months ago

Closed 8 months ago

#29304 closed Bug (duplicate)

QuerySet.bulk_create() fails with "ORA-01790: expression must have same datatype as corresponding expression"

Reported by: isergey Owned by: nobody
Component: Database layer (models, ORM) Version: 2.0
Severity: Normal Keywords:
Cc: felixxm Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

I have two models:

class Record(models.Model):
    hash = models.CharField(max_length=32)
    source = models.ForeignKey(Source, on_delete=models.CASCADE)
    create_date = models.DateTimeField(db_index=True)
    update_date = models.DateTimeField(db_index=True)
    deleted = models.BooleanField(default=False, db_index=True)


class RecordContent(models.Model):
    record = models.OneToOneField(Record, primary_key=True, on_delete=models.CASCADE)
    content = models.TextField(max_length=100 * 1024)

In MySQL this function works fine:

def _create_records(record_containers):
    records = []
    record_contents = []
    for record_container in record_containers:
        records.append(record_container['record'])
        record_contents.append(record_container['content'])

    models.Record.objects.bulk_create(records)
    models.RecordContent.objects.bulk_create(record_contents) # in Oracle ORA-01790: expression must have same datatype as corresponding expression

But in Oracle this code thows exception: ORA-01790: expression must have same datatype as corresponding expression

If refactor the function _create_records:

def _create_records(record_containers):
    for record_container in record_containers:
        models.Record.objects.bulk_create([record_container['record']])
        models.RecordContent.objects.bulk_create([record_container['content']])

there is no exception is thrown.

What happens?

Change History (5)

comment:1 Changed 8 months ago by isergey

Description: modified (diff)

comment:2 Changed 8 months ago by isergey

Description: modified (diff)

comment:3 Changed 8 months ago by Tim Graham

Component: UncategorizedDatabase layer (models, ORM)
Description: modified (diff)
Summary: Bulk Create bug in ORACLEQuerySet.bulk_create() fails with "ORA-01790: expression must have same datatype as corresponding expression"
Type: UncategorizedBug

What version of Django are you using? It might be a duplicate of #22669 (fixed in Django 2.0). If not, please try to minimize the code to reproduce the issue, including the data that causes the crash.

comment:4 Changed 8 months ago by felixxm

Cc: felixxm added

comment:5 Changed 8 months ago by Tim Graham

Resolution: duplicate
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top