Skip to content

[FIX] - catch missing orgbook entity and improve logging #3301

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

Merged
merged 45 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
03e7aa8
data typing issues and clean up
Jsyro Nov 6, 2024
962f5e9
better logging
Jsyro Nov 7, 2024
1af241d
better logging of errors
Jsyro Nov 7, 2024
66e22c4
list of tuples
Jsyro Nov 7, 2024
4537f18
add celery decorator
Jsyro Nov 7, 2024
fb883b5
rename var to match envvar
Jsyro Nov 7, 2024
6f49d48
Merge branch 'develop' into feature/issue-to-orgbook-w-publisher
Jsyro Nov 7, 2024
687e03e
credential per mine_party_appt produces duplicates.
Jsyro Nov 7, 2024
6cd313b
Merge branch 'develop' into feature/issue-to-orgbook-w-publisher
Jsyro Nov 7, 2024
be179c2
wrong class
Jsyro Nov 7, 2024
2652d0f
don't invoke if being used by celery
Jsyro Nov 7, 2024
7ccd3c0
query must excluded deleted permit_amendments
Jsyro Nov 7, 2024
6ce7067
add check if cred not created
Jsyro Nov 8, 2024
a6e44a3
improve logging of problem states
Jsyro Nov 8, 2024
a95574b
Merge branch 'develop' into feature/issue-to-orgbook-w-publisher
Jsyro Nov 8, 2024
4ae3465
make date a date, formatting
Jsyro Nov 8, 2024
9e89270
revered received date, update issue_Date validator
Jsyro Nov 8, 2024
6758491
all datetimes, never dates
Jsyro Nov 8, 2024
f68c378
typo
Jsyro Nov 8, 2024
5f23ae3
names are important
Jsyro Nov 8, 2024
6f05801
only use datetime objects, no date objects
Jsyro Nov 8, 2024
410ddcc
better typing
Jsyro Nov 8, 2024
28b35f7
ensure second is non-zero for datetime
Jsyro Nov 8, 2024
27fff76
oops
Jsyro Nov 8, 2024
2a4a118
brackets matter
Jsyro Nov 8, 2024
9bd7762
what is happening?
Jsyro Nov 8, 2024
7b901f2
scoping
Jsyro Nov 8, 2024
8546322
factories making dates, should be datetimes.
Jsyro Nov 8, 2024
46aeab5
idk why that today generator suck
Jsyro Nov 8, 2024
c7e04f0
pass callable
Jsyro Nov 8, 2024
2332d50
what
Jsyro Nov 8, 2024
d32a875
Merge branch 'develop' into feature/issue-to-orgbook-w-publisher
Jsyro Nov 8, 2024
ec05069
use jank
Jsyro Nov 8, 2024
ce25b82
use work
Jsyro Nov 8, 2024
14ab519
huh?
Jsyro Nov 8, 2024
a1d0b46
typing dates as dates. some db columns are dates, others aren'
Jsyro Nov 8, 2024
7af67e9
dates
Jsyro Nov 8, 2024
114a987
handling incoming datetime for date column
Jsyro Nov 8, 2024
39042c2
probably failing on date comparison
Jsyro Nov 9, 2024
ffed5f6
type hinting is good
Jsyro Nov 9, 2024
6f117b0
clean up logging
Jsyro Nov 12, 2024
8f34192
columns are dates
Jsyro Nov 12, 2024
0093b9c
received date is parsed to datetime
Jsyro Nov 12, 2024
1202685
expand on type hinting
Jsyro Nov 12, 2024
d963492
pass function, not value
Jsyro Nov 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@

from app.api.constants import *
from app.api.mines.permits.permit_amendment.models.permit_amendment_document import (
PermitAmendmentDocument,
)
PermitAmendmentDocument, )
from app.api.mines.permits.permit_conditions.models.permit_conditions import (
PermitConditions,
)
PermitConditions, )
from app.api.utils.models_mixins import AuditMixin, Base, SoftDeleteMixin
from app.api.verifiable_credentials.aries_constants import IssueCredentialIssuerState
from app.extensions import db
Expand All @@ -30,7 +28,7 @@ class PermitAmendment(SoftDeleteMixin, AuditMixin, Base):
permit_amendment_guid = db.Column(UUID(as_uuid=True), server_default=FetchedValue())
permit_id = db.Column(db.Integer, db.ForeignKey('permit.permit_id'), nullable=False)
received_date = db.Column(db.DateTime, nullable=False)
issue_date: date = db.Column(db.DateTime, nullable=False)
issue_date = db.Column(db.DateTime, nullable=False)
authorization_end_date = db.Column(db.DateTime, nullable=False)
permit_amendment_status_code = db.Column(
db.String(3), db.ForeignKey('permit_amendment_status_code.permit_amendment_status_code'))
Expand Down
28 changes: 19 additions & 9 deletions services/core-api/app/api/verifiable_credentials/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from app.api.mines.permits.permit.models.permit import Permit
from app.api.mines.permits.permit_amendment.models.permit_amendment import PermitAmendment
from app.api.parties.party_appt.models.mine_party_appt import MinePartyAppointment
from app.api.verifiable_credentials.models.credentials import PartyVerifiableCredentialMinesActPermit
from app.api.verifiable_credentials.models.connection import PartyVerifiableCredentialConnection
from app.api.verifiable_credentials.models.orgbook_publish_status import PermitAmendmentOrgBookPublish
Expand Down Expand Up @@ -53,6 +54,7 @@ class UNTPCCMinesActPermit(cc.ConformityAttestation):
and mpa.mine_party_appt_type_code = 'PMT'
and mpa.deleted_ind = false
and m.major_mine_ind = true
and pa.deleted_ind = false

group by pa.permit_amendment_guid, pa.description, pa.issue_date, pa.permit_amendment_status_code, mpa.deleted_ind, pmt.permit_no, mpa.permit_id, poe.party_guid, p.party_name, poe.name_text, poe.registration_id
order by pmt.permit_no, pa.issue_date;
Expand Down Expand Up @@ -81,8 +83,9 @@ class W3CCred(BaseModel):
credentialSchema: List[dict]


def convert_date_to_iso_datetime(date: date) -> str:
return datetime(date.year, date.month, date.day, 0, 0, 0, tzinfo=ZoneInfo("UTC")).isoformat()
def convert_date_to_iso_datetime(datetime: datetime) -> str:
return datetime(
datetime.year, datetime.month, datetime.day, 0, 0, 0, tzinfo=ZoneInfo("UTC")).isoformat()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Have to check, just because we have a million issues with UTC times- this converts the datetime to UTC, not tells it that the timezone it has is UTC, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

datetime objects are natively timezone-unaware.

the python language is deprecating some of these methods in favour or producting timezone-aware datetime objects

well formed VCDM credentials required timezone codes, i could just append T00:00:00 to the string, but this is a more pythonic way to do that and is better understood by future devs

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What that means is existing datetime objects based on UTC don't know they are based on UTC, they are date+time with no timezone information. it's up to the code to know that it's based on UTC, or maybe postgres is automatically adding UTC information?

it's probably something that should become it's own task. to update the python to start using the new timezone-aware methods and classes, update the validators to require timezone-aware objects (or add it), then update remaining datetime values to have timezone information.

Copy link
Collaborator

Choose a reason for hiding this comment

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

👍
Sounds good. The db does automatically save it as UTC. I appreciate the documentation!



@celery.task()
Expand Down Expand Up @@ -272,7 +275,9 @@ def push_untp_map_data_to_publisher():
pa = PermitAmendment.find_by_permit_amendment_guid(row[0], unsafe=True)
pa_cred, new_id = VerifiableCredentialManager.produce_untp_cc_map_payload(
Config.CHIEF_PERMITTING_OFFICER_DID_WEB, pa)

if not pa_cred:
task_logger.warning(f"pa_cred could not be created for permit_amendment_guid={row[0]}")
continue
#only one assessment per credential
publish_payload = {
"type": "BCMinesActPermitCredential",
Expand Down Expand Up @@ -392,9 +397,7 @@ def collect_attributes_for_mines_act_permit_111(
credential_attrs["mine_commodity"] = ", ".join(
mine_commodity_list) if mine_commodity_list else None
credential_attrs["mine_no"] = permit_amendment.mine.mine_no
credential_attrs["issue_date"] = int(
permit_amendment.issue_date.strftime("%Y%m%d")) if is_feature_enabled(
Feature.VC_ANONCREDS_20) else permit_amendment.issue_date
credential_attrs["issue_date"] = int(permit_amendment.issue_date.strftime("%Y%m%d"))
# https://github.com/hyperledger/aries-rfcs/tree/main/concepts/0441-present-proof-best-practices#dates-and-predicates
credential_attrs["latitude"] = permit_amendment.mine.latitude
credential_attrs["longitude"] = permit_amendment.mine.longitude
Expand Down Expand Up @@ -461,17 +464,24 @@ def produce_untp_cc_map_payload(cls, did: str,
# "tsf_operating_count"
# "tsf_care_and_maintenance_count"

curr_appt = permit_amendment.permittee_appointments[0]
curr_appt: MinePartyAppointment = permit_amendment.permittee_appointments[0]
for pmt_appt in permit_amendment.permittee_appointments:
#find the last permittee appointment relevant to the amendment issue date.
if (pmt_appt.start_date or date(year=1900)) <= permit_amendment.issue_date:
if (pmt_appt.start_date or datetime(year=1900)) <= permit_amendment.issue_date:
curr_appt = pmt_appt
else:
break

orgbook_entity = curr_appt.party.party_orgbook_entity
if not orgbook_entity:
current_app.logger.warning("No Orgbook Entity, do not produce Mines Act Permit UNTP CC")
if curr_appt.party:
current_app.logger.warning(
f"No Orgbook Entity for party_guid={curr_appt.party.party_guid}, could not produce Mines Act Permit UNTP CC"
)
else:
current_app.logger.error(
f"No party for mine_party_appointment_id={curr_appt.mine_party_appt_id}, that shouldn't be possible"
)
return None, None

untp_party_cpo = base.Identifier(
Expand Down
Loading
Loading