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: Add manufacture_data django command #369

Merged
merged 1 commit into from Jan 16, 2024

Conversation

marlonkeating
Copy link
Contributor

@marlonkeating marlonkeating commented Dec 11, 2023

Description:

This change migrates the manufacture_data django command introduced in openedx/edx-enterprise#1826 to where it can be used outside of the enterprise ecosystem.

JIRA

ENT-7636

Installation/Testing instructions:

In Devstack, prior to being pushed to PyPi

  1. Copy to IDA VM's python path
    Example: docker cp ~/edx-repos/edx-django-utils/. {container uuid}:/lib/
    Where container uuid can be found by running docker ps
  2. Create management command that inherits from manufacture_data.command and imports model factories (Example: feat: Add manufacture_data django command enterprise-catalog#734)
  3. Run manufacture_data management command
    Example:
    python ./manage.py manufacture_data --model enterprise_catalog.apps.catalog.models.EnterpriseCatalog --title "Test Catalog"

Merge checklist:

  • All reviewers approved
  • CI build is green
  • Version bumped
  • Changelog record added
  • Documentation updated (not only docstrings)
  • Commits are squashed

Post merge:

@johnnagro johnnagro marked this pull request as ready for review December 11, 2023 19:32
@johnnagro johnnagro marked this pull request as draft December 11, 2023 19:32
.venv-3.8/pyvenv.cfg Outdated Show resolved Hide resolved
@robrap
Copy link
Collaborator

robrap commented Dec 11, 2023

Hello @marlonkeating. I know this is just a draft. I'm going to check in with arch-bom about the planned how and where for developer data. See edx/edx-arch-experiments#138

@marlonkeating marlonkeating force-pushed the mkeating/provisioning-scripts branch 4 times, most recently from 24304f1 to 0c6b27f Compare December 19, 2023 20:15
@marlonkeating marlonkeating marked this pull request as ready for review December 19, 2023 20:16
@marlonkeating marlonkeating force-pushed the mkeating/provisioning-scripts branch 6 times, most recently from e026502 to 3ff5f28 Compare January 5, 2024 13:40
@marlonkeating marlonkeating force-pushed the mkeating/provisioning-scripts branch 4 times, most recently from 5b8f80c to 6321589 Compare January 12, 2024 16:03
Copy link

@alex-sheehan-edx alex-sheehan-edx left a comment

Choose a reason for hiding this comment

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

Small comments/question mostly about documentation. Otherwise looks great and I'm excited to get this released!

edx_django_utils/data_generation/README.rst Show resolved Hide resolved

Unsupported Cases
-----------------
One limitation of this script is that it can only fetch or customize, you cannot customize a specified, existing FK:

Choose a reason for hiding this comment

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

you cannot customize a specified, existing FK:

or customizations to any subclasses/FK's to the specified to an existing object

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Edited for more clarity

edx_django_utils/data_generation/README.rst Outdated Show resolved Hide resolved
edx_django_utils/data_generation/tests/apps.py Outdated Show resolved Hide resolved
defaults = dict(
defaults._get_kwargs(), **arg_options
)
# Commented out section allows for unknown options to be passed to the command

Choose a reason for hiding this comment

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

I feel like this should go to the top of the method, explaining why we have to redefine the core django function in the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Went ahead and removed the commented out code, and explained the disabled arg checking at the top. I figure if we ever want that code back, we know where we originally got it.

Copy link
Contributor

@rgraber rgraber left a comment

Choose a reason for hiding this comment

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

Mostly nits and requests for clarification. Also, I'm surprised that this passed the doc linter. That's not on you, but I think something is up with the way the linter is configured. It should complain when docstrings are not something like

def my_func(arg1):
    Does an important thing.

   More information about important thing.
   Arguments:
       arg1: Is a thing

CHANGELOG.rst Outdated Show resolved Hide resolved
README.rst Outdated
@@ -23,13 +23,12 @@ This repository includes shared utilities for:

* `Logging Utilities`_: Includes log filters and an encrypted logging helper.

* `Monitoring Utilities`_: Includes Middleware and utilities for enhanced monitoring.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, that wasn't my intention. It may have been a merge issue that I missed.


Unsupported Cases
-----------------
One limitation of this script is that it can only fetch or customize, you cannot customize a specified, existing FK:
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand this sentence. Can you elaborate more on what we are fetching and customizing? And do you mean we cannot customize an existing object? There's not really a notion of customizing keys.
I also think modify makes more sense than customize but that's minor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated based on @alex-sheehan-edx's comments

`./manage.py lms manufacture_data --model enterprise.models.EnterpriseCustomerUser --enterprise_customer <invalid uuid>`

we'd get:
`CommandError: Provided FK value: <SOMETHING BAD> does not exist on EnterpriseCustomer`
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
`CommandError: Provided FK value: <SOMETHING BAD> does not exist on EnterpriseCustomer`
`CommandError: Provided FK value: <invalid uuid> does not exist on EnterpriseCustomer`

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, made that correction based on @alex-sheehan-edx 's comment


def is_not_pascal(string):
"""
helper method to detect if strings are not Pascal case.
Copy link
Contributor

Choose a reason for hiding this comment

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

An example of Pascal case would be useful here (I'd never heard the term before)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CapWords is how it's named in the python documentation, added note in the comments.


def __str__(self, level=0):
"""
Overridden str method to allow for proper tree printing
Copy link
Contributor

Choose a reason for hiding this comment

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

An example of the expected output would be helpful

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 think the best example is in the unit tests. I don't know that there's a more compact way to illustrate the output than by reading the code here, and referencing the unit test.

edx_django_utils/data_generation/README.rst Show resolved Hide resolved
@marlonkeating marlonkeating force-pushed the mkeating/provisioning-scripts branch 2 times, most recently from 6deb17f to aeb961d Compare January 16, 2024 19:52
Copy link
Contributor

@rgraber rgraber left a comment

Choose a reason for hiding this comment

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

One incredibly obnoxious nit, otherwise looks great! Thanks for all your hard work on this.


def build_tree_from_field_list(list_of_fields, provided_factory, base_node, customization_value):
"""
Builds a non-binary tree of nodes based on a list of children nodes, using a base node and it's associated data
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit]

Suggested change
Builds a non-binary tree of nodes based on a list of children nodes, using a base node and it's associated data
Builds a non-binary tree of nodes based on a list of children nodes, using a base node and its associated data

test: Fix test configuration

test: improve test coverage

test: case for nonstandard model casing

test: more coverage

docs: Add documentation for manufacture_data

docs: Setup documentation for manufacture_data

style: Fix code quality errors

style: Fix pycodestyle errors

style: Fix isort errors

test: remove unneeded test code

test: error test coverage

fix: support field names that don't match snake-cased model names

test: remove unused code branches

fix: Handle abstract classes during factory discovery

fix: Clean up node tree logging

docs: Update documentation

docs: Update documentation based on comments

chore: fix trailing whitespace

chore: fix typo
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.

None yet

4 participants