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

ORA-01400: cannot insert NULL into ("OT_TOOL_DEV"."SILK_REQUEST"."PROF_FILE") #450

Open
dbiegunski opened this issue Oct 19, 2020 · 5 comments · May be fixed by #619
Open

ORA-01400: cannot insert NULL into ("OT_TOOL_DEV"."SILK_REQUEST"."PROF_FILE") #450

dbiegunski opened this issue Oct 19, 2020 · 5 comments · May be fixed by #619

Comments

@dbiegunski
Copy link

django-silk with Oracle not working properly.

IntegrityError at /
ORA-01400: cannot insert NULL into ("OT_TOOL_DEV"."SILK_REQUEST"."PROF_FILE")

pip install https://github.com/jazzband/django-silk.git@09338c1e3ecea1f521eeaee79e6e4a78960fc0d3#egg=django_silk

django-silk (4.1.1.dev3+g09338c1)
Python 3.8.0
Django 2.2.16

@dualmacops
Copy link

Same problem
ORA-01400: cannot insert NULL into ("SILK_REQUEST"."PROF_FILE")

@dualmacops
Copy link

When made the fiel nulleable silk summary returns:

ORA-00932: inconsistent datatypes: expected - got NCLOB

@matt-hoskins
Copy link

I've just bumped into this and dug into the underlying cause. It's a side effect of silk originally defining the prof_file FileField as null=True and later changing it to be blank=True and there being a bug in django handling such migrations under Oracle (under Oracle empty strings are saved as NULL values so Django shouldn't have changed the column to become NOT NULL). I've logged a django ticket for the issue: https://code.djangoproject.com/ticket/33080

You can work around it by making the column nullable:
alter table silk_request modify (prof_file NULL);

After I made this change silk was able to log requests without error for me.

Although you say in a comment that you got an ORA-00932 when you made the field nullable I think you must have made some other change or something else going on - prof_file is stored as NVCHAR2(300) and not NCLOB (did you try making the change by editing the models for silk instead of just changing the database column?)

@matt-hoskins
Copy link

Regarding the NCLOB issue - that is a separate Oracle-related quirk which I've now also experienced - you get that trying to access silk's summary view of requests (i.e. it is a different issue) and it's triggered by these two lines individually in views/summary.py ...
r = models.Request.objects.filter(view_name=view, *filters).annotate(t=Sum('queries__time_taken')).order_by('-t')[0]
r = models.Request.objects.filter(view_name=view, *filters).annotate(t=Count('queries')).order_by('-t')[0]

That is an issue caused by Oracle not liking GROUP BY on NCLOB (basically NCLOB is how TextField columns are represented under oracle by django and doing a count of a many to many related type causes django to generate a query which does a group by of all fields for the model you're querying against).

See: https://code.djangoproject.com/ticket/24096

It's possible to alter code to work around this issue by either using .defer on all text field columns (I think django have ruled out, based on that ticket, doing that automatically) or using .only on just the id column so that's the only field fetched by the query.

So a quick change to the two lines I mentioned above would be to:
r = models.Request.objects.filter(view_name=view, *filters).annotate(t=Sum('queries__time_taken')).order_by('-t').only('id')[0]
r = models.Request.objects.filter(view_name=view, *filters).annotate(t=Count('queries')).order_by('-t').only('id')[0]

That would incur the performance penalty of the field values on r being deferred, so loaded by another query when accessed on r (so the author of silk may be disinclined to put that change in just to help out anyone with the misfortune to be needing to deal with Oracle!).

@SebCorbin
Copy link
Contributor

Should be solved by #258

@SebCorbin SebCorbin linked a pull request Oct 31, 2022 that will close this issue
@SebCorbin SebCorbin linked a pull request Oct 31, 2022 that will close this issue
@SebCorbin SebCorbin removed the has PR label Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants