uber / charlatan Goto Github PK
View Code? Open in Web Editor NEWA Python library to efficiently manage and install database fixtures
Home Page: https://charlatan.readthedocs.org/en/latest/
License: Other
A Python library to efficiently manage and install database fixtures
Home Page: https://charlatan.readthedocs.org/en/latest/
License: Other
Multiple file support for fixtures (c5d027b) is great!
I'd like to go one step further and be able to specify a directory containing all my fixtures and have that loaded
The doc for FixturesManager
states that it accepts "list_or_str" of filenames. However, it always calls extend
on the given parameter. If the input is a list, appending a list to a list gives you a list of lists. In this case self.filenames
should be extending the given input.
Currently depend_on
appears to be ignored on collections.
I can't see how to use depend_on
for either the parent collection or the child objects. Ideally I'd like the whole collection to depend on another collection.
Charlatan seems like a very nice way to manage and load fixture data. Is it possible to go the other way, and generate fixtures from an existing database?
Django's fixture management lets you do this via manage.py dumpdata
. It's a useful way to capture database state to something that's human readable/editable and less brittle than sqldump.
Thanks.
Currently if we want to override a field for a fixture,
we have to use install_fixture like so
self.install_fixture('foo', overrides={'a': 'baz'})
self.install_fixtures((
'foo',
'bar',
'baz'
))
however, the ability to do this inline would be nice:
self.install_fixtures((
'foo',
'bar',
'baz',
('foo', overrides={'a': 'baz'})
))
The install_all_fixtures() method ignores fixtures declared with the inherit_from attribute.
I'm using version 0.4.5
This could be a problem with pyyaml itself.
When creating fixtures without models and nesting !now
only first level is evaluated
This yaml definition:
simple_dict:
fields:
created_at: !now
nested:
created_at: !now
produces this output:
{
'created_at': datetime.datetime(2015, 11, 25, 17, 27, 3, 119923, tzinfo=<UTC>),
'nested': {
'created_at': <function configure_yaml.<locals>.now_constructor.<locals>.get_now at 0x1052cbbf8>
}
}
Cheers,
Jakub
When I reference a fixture in a post_creation
section using !rel
, it is created and added to relationship but I have to manually run an extra commit afterwards.
Results in code like:
fix.install_fixture(name)
db.session.commit()
Feels like I shouldn't need to do this...?
Error resolving anonymous references based on list of objects:
(...)
charlatan/utils.pyc in richgetter(obj, path)
174 obj = getattr(obj, name)
175 continue
--> 176 obj = obj[name]
177
178 return obj
TypeError: list indices must be integers, not str
This happens loading the fixture
>>> import charlatan
>>> fm = charlatan.FixturesManager(session)
>>> fm.load('fixtures.yaml', 'app.models')
# Specific index is OK
>>> fm.get_fixture('department.0')
Department
# Whole collection raises error
>>> fm.get_fixture('departments')
(...)
TypeError: list indices must be integers, not str
office:
model: Office
offices:
inherit_from: office
objects:
-
name: 'Office0'
-
name: 'Office1'
department:
model: Department
departments:
inherit_from: department
objects:
-
name: 'Department0'
office: !rel offices.0
-
name: 'Department1'
office: !rel offices.1
It works using keys 0, 1 for offices instead of a list, but it changes the get_fixture
return type from list
to dict
.
FixtureManager's get_fixtures
method accepts the builder instance but does not pass it further in nested call to get_fixture
method.
The default SQLAlchemy builder (InstallAndSave
) commits the session on each individual fixture.
In some cases, it may be more desirable to allow all fixtures to be instantiated added to the session before committing the entire session. For example, if any semantic error occurs (valid YAML, but invalid for the SQLAlchemy model), the application may wish to roll back all fixture changes rather than commit partial data.
This could be done by adding a autocommit
boolean kwarg to the __call__
method that would skip this session commit call.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.