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

feat: customizable management command to generate local enterprise data #1826

Merged
merged 2 commits into from
Aug 1, 2023

Conversation

alex-sheehan-edx
Copy link
Contributor

@alex-sheehan-edx alex-sheehan-edx commented Jul 26, 2023

How to use this work:

Upon invoking the command, supply a model param (--model) that is a complete path to a model that has a corresponding test factory ie

./manage.py lms manufacture_data --model enterprise.models.EnterpriseCustomer

This will generate an enterprise customer record with place holder values according to the test factory

'EnterpriseCustomer' fields: {}

We can also provide customizations to the record being generated, ie

./manage.py lms manufacture_data --model enterprise.models.EnterpriseCustomer --name "FRED"

which will produce the customized record:

'EnterpriseCustomer' fields: {'name': 'FRED'}

we can also supply parent model/subfactory customizations as well:

./manage.py lms manufacture_data --model enterprise.models.EnterpriseCustomerCatalog --enterprise_customer__site__name "Fred" --enterprise_catalog_query__title "JOE SHMO" --title "who?" will result in

'EnterpriseCustomerCatalog' fields: {'title': 'who?'}
	'EnterpriseCustomer' fields: {}
		'Site' fields: {'name': 'Fred'}
	'EnterpriseCatalogQuery' fields: {'title': 'JOE SHMO'}

Note the non subclass customization --title "who?" is applied to the specified model EnterpriseCustomerCatalog

But say we want to supply an existing record as a FK to our object:

./manage.py lms manufacture_data --model enterprise.models.EnterpriseCustomerUser --enterprise_customer 994599e6-3787-48ba-a2d1-42d1bdf6c46e

we get:

'EnterpriseCustomerUser' fields: {}
	'EnterpriseCustomer' PK: 994599e6-3787-48ba-a2d1-42d1bdf6c46e

or we can do something like:

./manage.py lms manufacture_data --model enterprise.models.EnterpriseCustomerUser --enterprise_customer__site 9 --enterprise_customer__name "joe"

which would yield:

'EnterpriseCustomerUser' fields: {}
	'EnterpriseCustomer' fields: {'name': 'joe'}
		'Site' PK: 9

but if you try and get something that doesn't exist...

./manage.py lms manufacture_data --model enterprise.models.EnterpriseCustomerUser --enterprise_customer <SOMETHING BAD>

we'd get:

CommandError: Provided FK value: <SOMETHING BAD> does not exist on EnterpriseCustomer

another limitation of this script is that it can only fetch or customize, you cannot customize a specified, existing FK...

./manage.py lms manufacture_data --model enterprise.models.EnterpriseCustomerUser --enterprise_customer__site__name "fred" --enterprise_customer 994599e6-3787-48ba-a2d1-42d1bdf6c46e

would yield a

CommandError: This script does not support customizing provided existing objects

https://2u-internal.atlassian.net/browse/ENT-7403

Merge checklist:

  • Any new requirements are in the right place (do not manually modify the requirements/*.txt files)
    • base.in if needed in production but edx-platform doesn't install it
    • test-master.in if edx-platform pins it, with a matching version
    • make upgrade && make requirements have been run to regenerate requirements
  • make static has been run to update webpack bundling if any static content was updated
  • ./manage.py makemigrations has been run
    • Checkout the Database Migration Confluence page for helpful tips on creating migrations.
    • Note: This must be run if you modified any models.
      • It may or may not make a migration depending on exactly what you modified, but it should still be run.
    • This should be run from either a venv with all the lms/edx-enterprise requirements installed or if you checked out edx-enterprise into the src directory used by lms, you can run this command through an lms shell.
      • It would be ./manage.py lms makemigrations in the shell.
  • Version bumped
  • Changelog record added
  • Translations updated (see docs/internationalization.rst but also this isn't blocking for merge atm)

Post merge:

  • Tag pushed and a new version released
    • Note: Assets will be added automatically. You just need to provide a tag (should match your version number) and title and description.
  • After versioned build finishes in GitHub Actions, verify version has been pushed to PyPI
    • Each step in the release build has a condition flag that checks if the rest of the steps are done and if so will deploy to PyPi.
      (so basically once your build finishes, after maybe a minute you should see the new version in PyPi automatically (on refresh))
  • PR created in edx-platform to upgrade dependencies (including edx-enterprise)
    • This must be done after the version is visible in PyPi as make upgrade in edx-platform will look for the latest version in PyPi.
    • Note: the edx-enterprise constraint in edx-platform must also be bumped to the latest version in PyPi.

@alex-sheehan-edx alex-sheehan-edx marked this pull request as draft July 26, 2023 16:37
@alex-sheehan-edx alex-sheehan-edx force-pushed the asheehan-edx/ENT-7403-provisioning-scripts branch 12 times, most recently from 6ac4cfc to 2bda6f1 Compare July 26, 2023 21:04
@alex-sheehan-edx alex-sheehan-edx force-pushed the asheehan-edx/ENT-7403-provisioning-scripts branch 5 times, most recently from bd5b43c to 3812217 Compare July 27, 2023 20:28
@adamstankiewicz
Copy link
Member

@alex-sheehan-edx [curious] Just seeking clarification on the approach here: how does this new command relate to the existing seed_enterprise_devstack_data command? Is the intent to deprecate that existing one in favor of this new one? It might be confusing to have 2 commands documented doing seemingly somewhat similar things.

@alex-sheehan-edx alex-sheehan-edx force-pushed the asheehan-edx/ENT-7403-provisioning-scripts branch 3 times, most recently from 23dfe4a to bfad7f3 Compare July 28, 2023 17:36
@alex-sheehan-edx
Copy link
Contributor Author

@alex-sheehan-edx [curious] Just seeking clarification on the approach here: how does this new command relate to the existing seed_enterprise_devstack_data command? Is the intent to deprecate that existing one in favor of this new one? It might be confusing to have 2 commands documented doing seemingly somewhat similar things.

@adamstankiewicz The hope is to deprecate the old one! But there are also some use cases for this that I think apply outside of that script that I will try and highlight 😄

@alex-sheehan-edx alex-sheehan-edx force-pushed the asheehan-edx/ENT-7403-provisioning-scripts branch 3 times, most recently from 8f34217 to f2c7060 Compare July 31, 2023 01:54
@alex-sheehan-edx alex-sheehan-edx force-pushed the asheehan-edx/ENT-7403-provisioning-scripts branch from f2c7060 to da9dcfc Compare July 31, 2023 02:18
Copy link
Contributor

@johnnagro johnnagro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great so far. would like to see some example scripts which utilize it.

test_utils/factories.py Outdated Show resolved Hide resolved
requirements/common_constraints.txt Outdated Show resolved Hide resolved
enterprise/management/commands/manufacture_factory_data.py Outdated Show resolved Hide resolved
@alex-sheehan-edx alex-sheehan-edx force-pushed the asheehan-edx/ENT-7403-provisioning-scripts branch from dafb7fc to f4d02bf Compare July 31, 2023 18:57
@alex-sheehan-edx alex-sheehan-edx marked this pull request as ready for review July 31, 2023 19:11
@alex-sheehan-edx alex-sheehan-edx force-pushed the asheehan-edx/ENT-7403-provisioning-scripts branch 3 times, most recently from 69a2f9b to 76b9123 Compare July 31, 2023 19:18
@alex-sheehan-edx alex-sheehan-edx force-pushed the asheehan-edx/ENT-7403-provisioning-scripts branch 4 times, most recently from 016db49 to d5b83b9 Compare July 31, 2023 20:33
from django.core.management.base import CommandError


def call_command(command_name, *args, **options):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to redefine call_command to allow us to use unrecognized args

@alex-sheehan-edx alex-sheehan-edx force-pushed the asheehan-edx/ENT-7403-provisioning-scripts branch 6 times, most recently from 16400d1 to 00700c0 Compare August 1, 2023 14:16
@alex-sheehan-edx alex-sheehan-edx force-pushed the asheehan-edx/ENT-7403-provisioning-scripts branch 3 times, most recently from bea89b6 to c508a5d Compare August 1, 2023 14:41
@alex-sheehan-edx alex-sheehan-edx force-pushed the asheehan-edx/ENT-7403-provisioning-scripts branch from c508a5d to da5e1e1 Compare August 1, 2023 15:02
@alex-sheehan-edx alex-sheehan-edx merged commit 8482100 into master Aug 1, 2023
@alex-sheehan-edx alex-sheehan-edx deleted the asheehan-edx/ENT-7403-provisioning-scripts branch August 1, 2023 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants