-
Notifications
You must be signed in to change notification settings - Fork 1
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
RAS-1228: Bug: Party service workers getting 139 SIGSEGV errors and restarting #433
Open
SteveScorfield
wants to merge
4
commits into
main
Choose a base branch
from
fix-party-service-139-sigsegv-error-nin-test-branch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import logging | ||
|
||
import structlog | ||
from werkzeug.exceptions import BadRequest | ||
|
||
from ras_party.models import models | ||
|
||
logger = structlog.wrap_logger(logging.getLogger(__name__)) | ||
|
||
|
||
def get_respondents_associations(respondents): | ||
associations = [] | ||
for business_respondent in respondents: | ||
respondent_dict = { | ||
"partyId": business_respondent.respondent.party_uuid, | ||
"businessRespondentStatus": business_respondent.respondent.status.name, | ||
} | ||
enrolments = business_respondent.enrolment | ||
respondent_dict["enrolments"] = [] | ||
for enrolment in enrolments: | ||
enrolments_dict = { | ||
"surveyId": enrolment.survey_id, | ||
"enrolmentStatus": models.EnrolmentStatus(enrolment.status).name, | ||
} | ||
respondent_dict["enrolments"].append(enrolments_dict) | ||
associations.append(respondent_dict) | ||
return associations | ||
|
||
|
||
def get_attributes_for_collection_exercise(model_attributes, collection_exercise_id=None): | ||
if collection_exercise_id: | ||
for attributes in model_attributes.attributes: | ||
if attributes.collection_exercise == collection_exercise_id: | ||
return attributes | ||
|
||
try: | ||
return next((attributes for attributes in model_attributes.attributes if attributes.collection_exercise)) | ||
except StopIteration: | ||
logger.error("No active attributes for business", reference=model_attributes.business_ref, status=400) | ||
raise BadRequest("Business with reference does not have any active attributes.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I like the naming of this. But I couldn't think what would be a good name for this. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from ras_party.models import model_functions | ||
|
||
|
||
def to_unified_dict(model, collection_exercise_id=None, attributes_required=False, retrieve_associations=True): | ||
attributes = model_functions.get_attributes_for_collection_exercise(model, collection_exercise_id) | ||
unified_dict = { | ||
"id": model.party_uuid, | ||
"sampleUnitRef": model.business_ref, | ||
"sampleUnitType": model.UNIT_TYPE, | ||
"sampleSummaryId": attributes.sample_summary_id, | ||
"name": attributes.attributes.get("name"), | ||
"trading_as": attributes.attributes.get("trading_as"), | ||
} | ||
if attributes_required: | ||
unified_dict["attributes"] = attributes.attributes | ||
if retrieve_associations: | ||
unified_dict["associations"] = model_functions.get_respondents_associations(model.respondents) | ||
|
||
return unified_dict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,13 @@ def get_business_by_ref(ref): | |
return jsonify(business) | ||
|
||
|
||
@business_view.route("/businesses/ref/reporting-unit-only/<ref>", methods=["GET"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not keen on the naming of this endpoint. Any ideas? |
||
def get_business_by_ref_only(ref): | ||
# This endpoint will retrieve the reporting unit only and not the associations. | ||
business = business_controller.get_business_by_ref(ref, retrieve_associations=True) | ||
return jsonify(business) | ||
|
||
|
||
@business_view.route("/businesses/sample/link/<sample>", methods=["PUT"]) | ||
def put_business_attributes_ce(sample): | ||
payload = request.get_json() or {} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to the retrieval of the enrolment DTO, I had to extract these functions out of the unified_business_party_functions.py