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

Add backward linkage of story to the topic it belongs. #6855

Merged
merged 10 commits into from
Jun 14, 2019

Conversation

DubeySandeep
Copy link
Member

Explanation

Add backward linkage of story to the topic it belongs.

Checklist

  • The PR title starts with "Fix #bugnum: ", followed by a short, clear summary of the changes. (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".)
  • The PR explanation includes the words "Fixes #bugnum: ..." (or "Fixes part of #bugnum" if the PR only partially fixes an issue).
  • The linter/Karma presubmit checks have passed.
    • These should run automatically, but if not, you can manually trigger them locally using python scripts/pre_commit_linter.py and bash scripts/run_frontend_tests.sh.
  • The PR is made from a branch that's not called "develop".
  • The PR has an appropriate "CHANGELOG: ..." label (If you are unsure of which label to add, ask the reviewers for guidance).
  • The PR follows the style guide.
  • The PR addresses the points mentioned in the codeowner checks for the files/folders changed. (See the codeowner's wiki page.)
  • The PR is assigned to an appropriate reviewer.
    • If you're a new contributor, please ask on Gitter for someone to assign a reviewer and don't tick this checkbox.
    • If you're not sure who the appropriate reviewer is, please assign to the issue's "owner" -- see the "talk-to" label on the issue. Do not only request the review but also add the reviewer as an assignee.

'Expected belongs_to_topic should be a string, received: %s' % (
self.belongs_to_topic))

if len(self.belongs_to_topic) != 12:
Copy link
Member Author

@DubeySandeep DubeySandeep Jun 6, 2019

Choose a reason for hiding this comment

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

@seanlip, Can you give your suggestion on these questions:
(belongs_to_topic = the topic id to which the story belongs)

  • Do we need to expose belongs_to_topic value to domain layer as we don't expect users to change this value?
  • If yes to the above question, then do we have to validate the topic_id? (note we do not validate the story_id)

@aks681, is there any specific reason for using created_on and last_updated in the domain layer?

Copy link
Member

Choose a reason for hiding this comment

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

"belongs_to_topic" sounds like a boolean. Maybe corresponding_topic_id or something like that.

Yes, expose to domain layer. Domain layer is where the logic is.

No need to validate topic ID.

Copy link
Contributor

Choose a reason for hiding this comment

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

I remember using collections as a reference when creating the new structure models and it had those 2 fields. So, I added that here as well.
I don't think you need to validate the existence of the topic, though you can make sure it's a 12 character string. I think the former is usually done in the controller layer. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I've done the validation check for the existence of topic in the service layer. Removed the simple validation check for the topic id from the domain layer.

Copy link
Member

@seanlip seanlip left a comment

Choose a reason for hiding this comment

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

Thanks @DubeySandeep! I took a quick glance at the overall structure, but woudl defer the more thorough review to @aks681.

One thing I'm confused about is -- shouldn't we have some code that handles stuff like "story added to topic", "story deleted from topic" (and adjusts the topic linkages accordingly)? I can't see where that code lives, but perhaps I'm missing it.

utils.py Outdated
@@ -487,7 +487,10 @@ def generate_random_string(length):
Returns:
str. Random string of specified length.
"""
return base64.urlsafe_b64encode(os.urandom(length))
random_string = ''
Copy link
Member

Choose a reason for hiding this comment

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

Oh, hm, interesting. Was the old function creating strings that were too short? Based on reading the python docs, I'm not sure I understand why that would happen... what's an example?

Copy link
Member Author

Choose a reason for hiding this comment

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

I wasn't sure about the case where we can have len(string) < length, but for me it was len(string) > length.

image

I read to docs in detail and I think it will only generate len(String) > length. I've made the changes!

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I see, urandom() creates a string of length 12 but urlsafe_b64encode might extend that. Thanks for clarifying!

We could alternatively just take the first "length" characters...

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

Copy link
Contributor

@aks681 aks681 left a comment

Choose a reason for hiding this comment

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

Just some minor comments, but looks good!
One question though, would this be required in the frontend?

'Expected belongs_to_topic should be a string, received: %s' % (
self.belongs_to_topic))

if len(self.belongs_to_topic) != 12:
Copy link
Contributor

Choose a reason for hiding this comment

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

I remember using collections as a reference when creating the new structure models and it had those 2 fields. So, I added that here as well.
I don't think you need to validate the existence of the topic, though you can make sure it's a 12 character string. I think the former is usually done in the controller layer. What do you think?


if story.id not in topic.canonical_story_ids + topic.additional_story_ids:
raise Exception(
'Expected story to belongs to the topic %s, but it is '
Copy link
Contributor

Choose a reason for hiding this comment

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

..belong to the topic.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

if story.id not in topic.canonical_story_ids + topic.additional_story_ids:
raise Exception(
'Expected story to belongs to the topic %s, but it is '
'neither a part of canonical story or the addition story of '
Copy link
Contributor

Choose a reason for hiding this comment

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

'the canonical stories or the additional stories'

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

@@ -58,6 +58,8 @@ class StoryModel(base_models.VersionedModel):
# The schema version for the story_contents.
story_contents_schema_version = (
ndb.IntegerProperty(required=True, indexed=True))
# The topic id to which the story belongs.
belongs_to_topic = ndb.StringProperty(indexed=False, required=False)
Copy link
Contributor

Choose a reason for hiding this comment

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

@seanlip. Will this cause issues with existing stories in the datastore?

Copy link
Member

Choose a reason for hiding this comment

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

No, I think it's fine. They'll just be set to None.

But I think indexed should be True. And once we've populated the story models on the test server correctly, we should make this required=True (is that right, @DubeySandeep? If so, we should add a TODO to do this.)

Copy link
Member Author

Choose a reason for hiding this comment

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

For now, I've changed both of the value to True once we will deploy the new branch to testserver we can add topic_id manually before start testing. I'll add an email (with the story id and corresponding topic id) to Sean for the same (for tracking).

Copy link
Contributor

@aks681 aks681 left a comment

Choose a reason for hiding this comment

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

LGTM!
Though, I'd suggest adding at least the simple basestring validation check to story_domain, as all other fields have their checks there also.
Also note, failing test.

@aks681 aks681 assigned DubeySandeep and unassigned aks681 Jun 12, 2019
@DubeySandeep
Copy link
Member Author

@aks681, I've fixed the tests and added validation check to story_domain.

@nithusha21, Can you please review this PR as a codeowner?

@codecov
Copy link

codecov bot commented Jun 13, 2019

Codecov Report

Merging #6855 into develop will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #6855      +/-   ##
===========================================
+ Coverage    95.68%   95.68%   +<.01%     
===========================================
  Files          371      371              
  Lines        51360    51429      +69     
===========================================
+ Hits         49143    49212      +69     
  Misses        2217     2217
Impacted Files Coverage Δ
core/storage/story/gae_models_test.py 100% <ø> (ø) ⬆️
core/controllers/topic_editor.py 84.43% <ø> (ø) ⬆️
core/controllers/story_viewer_test.py 100% <100%> (ø) ⬆️
core/tests/test_utils.py 95.72% <100%> (ø) ⬆️
utils_test.py 100% <100%> (ø) ⬆️
core/domain/story_services_test.py 100% <100%> (ø) ⬆️
core/storage/story/gae_models.py 100% <100%> (ø) ⬆️
core/controllers/topic_viewer_test.py 100% <100%> (ø) ⬆️
core/domain/story_services.py 83.94% <100%> (+0.38%) ⬆️
core/controllers/story_editor_test.py 100% <100%> (ø) ⬆️
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7074567...fc64194. Read the comment docs.

Copy link
Contributor

@nithusha21 nithusha21 left a comment

Choose a reason for hiding this comment

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

Just a couple of nits in the docstring. LGTM as a codeowner.

@@ -1281,13 +1281,16 @@ def save_new_story(
description: str. The high level description of the story.
notes: str. A set of notes, that describe the characters,
main storyline, and setting.
corresponding_topic_id: str. The topic id to which the story belongs
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
corresponding_topic_id: str. The topic id to which the story belongs
corresponding_topic_id: str. The id of the topic to which the story belongs.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

@@ -1281,13 +1281,16 @@ def save_new_story(
description: str. The high level description of the story.
notes: str. A set of notes, that describe the characters,
main storyline, and setting.
corresponding_topic_id: str. The topic id to which the story belongs
to.
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the second "to"

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

@@ -1317,6 +1321,8 @@ def save_new_story_with_story_contents_schema_v1(
description: str. The high level description of the story.
notes: str. A set of notes, that describe the characters,
main storyline, and setting.
corresponding_topic_id: str. The topic id to which the story belongs
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

@nithusha21 nithusha21 removed their assignment Jun 13, 2019
@DubeySandeep
Copy link
Member Author

@seanlip & @apb7, can you please review this PR as a codeowner?

Copy link
Member

@seanlip seanlip left a comment

Choose a reason for hiding this comment

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

No comments, this looks excellent IMO. Thanks @DubeySandeep (and @aks681 @nithusha21 for reviewing)!

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.

5 participants