Code

Opened 6 years ago

Closed 6 years ago

#6034 closed (wontfix)

Add boolean option 'load_fixtures' to the django command 'syncdb', default value is True.

Reported by: delimy@… Owned by: nobody
Component: Core (Management commands) Version: master
Severity: Keywords: syncdb
Cc: ringier-dev@… Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Add boolean option 'load_fixtures' to the django command 'syncdb', default value is True.
We use this option in tests, so load_fixtures=False will not commit a transaction, and we can rollback easily.
There are also other circumstances that we don't want the fixture to load automatically.

Attachments (1)

syncdb_no_fixture.diff (1.3 KB) - added by delimy@… 6 years ago.

Download all attachments as: .zip

Change History (5)

Changed 6 years ago by delimy@…

comment:1 Changed 6 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to wontfix
  • Status changed from new to closed

If you don't want your fixture to be automatically loaded, don't call your fixture initial_data, and manually load the fixture when you need it.

comment:2 Changed 6 years ago by delimy@…

The problem is that if you create a model in, for example, doctest, call_command('sync') will do a commit to database after loading fixtures.
We use rollback instead of flush, so it cause problem.

comment:3 Changed 6 years ago by favo

  • Cc ringier-dev@… added
  • Resolution wontfix deleted
  • Status changed from closed to reopened
  • Triage Stage changed from Unreviewed to Design decision needed

Hi russellm,

Thanks for your comment. I think it's not bad to give us more control on syncdb command.

django-admin.py syncdb --load_fixtures=False # Don't load fixture automatically. Default is True, so don't break current logic.

The only reason we need to do this like Delimy said above is:

we write some new model in doctest, to help us test our related model( think about you need test your generic tag system, you need a main model.)

"""
Create a test model
    >>> class TestModel(models.Model)
    ...     title = xxx
    >>> call_command('sync')
"""

we also changed django test framework to use rollback instead of flush db, which is more friendly(allow you use a exist db data to test rather than put everything to fixture. sometime fixture can't describe our test data, we have database view, something like this.). so the issue is with in syncdb command will call loaddata command. and in loaddata commend logic, it go into another transcation and commit at the end. which break outside transaction.

So we add an option to syncdb command to across, IMO it's not bad, it's cheap. However we can use django.core.management.sql method instead, of course.

comment:4 Changed 6 years ago by jacob

  • Resolution set to wontfix
  • Status changed from reopened to closed

I agree with Russ on this -- more options make for more confusing software. If you're running a custom test framework, you should make this change there.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.