#30115 closed Bug (fixed)
inspectdb on SQLite crashes when introspecting varchar primary key with TypeError: unhashable type: 'dict'
Reported by: | Can Sarıgöl | Owned by: | Nick Pope |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 2.2 |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I created a project with version 2.2a1 and run migrate after then run inspectdb. I got this error
class DjangoSession(models.Model): Traceback (most recent call last): File "./manage.py", line 21, in <module> main() File "./manage.py", line 17, in main execute_from_command_line(sys.argv) File "/Users/can/Documents/Contribute_projects/Tests/django2_2_alfa2/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line utility.execute() File "/Users/can/Documents/Contribute_projects/Tests/django2_2_alfa2/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/Users/can/Documents/Contribute_projects/Tests/django2_2_alfa2/venv/lib/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv self.execute(*args, **cmd_options) File "/Users/can/Documents/Contribute_projects/Tests/django2_2_alfa2/venv/lib/python3.7/site-packages/django/core/management/base.py", line 364, in execute output = self.handle(*args, **options) File "/Users/can/Documents/Contribute_projects/Tests/django2_2_alfa2/venv/lib/python3.7/site-packages/django/core/management/commands/inspectdb.py", line 34, in handle for line in self.handle_inspection(options): File "/Users/can/Documents/Contribute_projects/Tests/django2_2_alfa2/venv/lib/python3.7/site-packages/django/core/management/commands/inspectdb.py", line 131, in handle_inspection field_type, field_params, field_notes = self.get_field_type(connection, table_name, row) File "/Users/can/Documents/Contribute_projects/Tests/django2_2_alfa2/venv/lib/python3.7/site-packages/django/core/management/commands/inspectdb.py", line 239, in get_field_type field_type = connection.introspection.get_field_type(row.type_code, row) File "/Users/can/Documents/Contribute_projects/Tests/django2_2_alfa2/venv/lib/python3.7/site-packages/django/db/backends/sqlite3/introspection.py", line 65, in get_field_type if description.pk and field_type in {'BigIntegerField', 'IntegerField'}: TypeError: unhashable type: 'dict'
Change History (11)
comment:1 by , 6 years ago
Summary: | inspectdb, TypeError: unhashable type: 'dict' → inspectdb for sqlite3, TypeError: unhashable type: 'dict' |
---|
comment:2 by , 6 years ago
Component: | Uncategorized → Database layer (models, ORM) |
---|---|
Severity: | Normal → Release blocker |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
comment:5 by , 6 years ago
Easy pickings: | unset |
---|---|
Needs tests: | set |
Summary: | inspectdb for sqlite3, TypeError: unhashable type: 'dict' → inspectdb on SQLite crashes with TypeError: unhashable type: 'dict' |
Is that code untested or this caused by a version of SQLite that's untested on Jenkins?
comment:7 by , 6 years ago
>>> import sqlite3 >>> sqlite3.sqlite_version '3.24.0'
Bisected to a35d2a4510d5beec398b1007aaa26492d6aedf97 which was Refs #23748
comment:8 by , 6 years ago
Sorry about this. I clearly forgot to take the special case of a tuple of (field_type, field_params_dict)
into account, field_params_dict
being the source of the error.
It turns out that this special case was a hack to handle max_length
for CharField
on SQLite only which was introduced by 9ede371c85a97406eecb19974ab01163839636a0.
Since a9a773ff38a9fd28085e8b62b8a160c4e2ea5efb, size is returned by get_table_description()
on SQLite so row.internal_size
is always overriding the max_length
returned in field_params_dict
.
Here is a PR that fixes the issue by removing this legacy approach to handling max_length
.
comment:9 by , 6 years ago
Needs tests: | unset |
---|---|
Owner: | changed from | to
I think no tests should be needed as we're removing the code that caused the broken behaviour.
comment:10 by , 6 years ago
Summary: | inspectdb on SQLite crashes with TypeError: unhashable type: 'dict' → inspectdb on SQLite crashes when introspecting varchar primary key with TypeError: unhashable type: 'dict' |
---|---|
Triage Stage: | Accepted → Ready for checkin |
OK, yes, thanks for the report.
This works against 2.1.5 but errors as reported against 2.2a1: