Opened 14 years ago

Closed 11 years ago

#14300 closed Bug (fixed)

manage.py sqlcustom fails if models are in a submodule

Reported by: David Rogers Owned by: Fede Heinz
Component: Core (Management commands) Version: 1.2
Severity: Normal Keywords:
Cc: emyller@…, timograham@…, vlastimil@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This is similar to #6961, from what I've seen. According to the docs for 1.2:

Django provides a hook for passing the database arbitrary SQL that's executed just after the CREATE TABLE 
statements when you run syncdb. You can use this hook to populate default records, or you could also create
SQL functions, views, triggers, etc.

The hook is simple: Django just looks for a file called sql/<modelname>.sql, in your app directory, where 
<modelname> is the model's name in lowercase.

This doesn't work when the "models" module is a directory instead of a file, i.e. project/application/models/ vice project/application/models.py. Apparently, sqlcustom is using similar logic to what was described in #6961, since I can move my sql/ directory into the models/ directory - a la project/application/models/sql/ - and everything works.

Attachments (1)

customsql_model_package.patch (5.2 KB ) - added by Fede Heinz 14 years ago.
Fixes the bug, adds tests

Download all attachments as: .zip

Change History (14)

comment:1 by Fede Heinz, 14 years ago

Owner: changed from nobody to Fede Heinz

by Fede Heinz, 14 years ago

Fixes the bug, adds tests

comment:2 by Fede Heinz, 14 years ago

Has patch: set
Resolution: fixed
Status: newclosed
Triage Stage: UnreviewedAccepted

The attached patch fixes the bug, and adds tests to check that both cases (models module is a directory or a file) work.

comment:3 by Ramiro Morales, 14 years ago

Resolution: fixed
Status: closedreopened

Reopening. The fixed status is set when a commit lands in the code repository.

comment:4 by Julien Phalip, 14 years ago

Patch needs improvement: set
Severity: Normal
Type: Bug

Unittests are now preferred over doctests in the django codebase. Could you rewrite your tests accordingly? Thanks!

comment:5 by Aymeric Augustin, 13 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:6 by Aymeric Augustin, 13 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:7 by Evandro Myller, 13 years ago

Cc: emyller@… added

comment:8 by Claude Paroz, 12 years ago

#19338 and #19358 are duplicates.

comment:9 by Aymeric Augustin, 12 years ago

Status: reopenednew

comment:10 by Tim Graham, 11 years ago

Cc: timograham@… added
Patch needs improvement: unset

comment:11 by Tim Graham, 11 years ago

Also reported in #15519 the PR there addresses backwards incompatibility by searching both app/sql and app/models/sql with a DeprecationWarning if the latter is used. I'm not a huge fan of adding extra code and tests to support that for a release or two, but I'll do it if necessary.

in reply to:  11 comment:12 by Vlastimil Zíma, 11 years ago

Cc: vlastimil@… added

Replying to timo:

Also reported in #15519 the PR there addresses backwards incompatibility by searching both app/sql and app/models/sql with a DeprecationWarning if the latter is used. I'm not a huge fan of adding extra code and tests to support that for a release or two, but I'll do it if necessary.

In #15519:comment:2 jacob required to use both locations. My patch also contains a test. The patch does not apply, because of all the changes in tests, but it should be easy to fix.

Version 0, edited 11 years ago by Vlastimil Zíma (next)

comment:13 by Tim Graham <timograham@…>, 11 years ago

Resolution: fixed
Status: newclosed

In 31c13a99bb9ebdaf12ccab4e880c5da930d86e79:

Fixed #14300 -- Fixed initial SQL location if models is a package.

Thanks al_the_x for the report and fheinz for the draft patch.

Note: See TracTickets for help on using tickets.
Back to Top