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

fix(commands): it is now impossible to create a study with an empty id #1531

Conversation

MartinBelthle
Copy link
Contributor

No description provided.

@@ -334,6 +334,11 @@ def remove_layer(self, study: RawStudy, layer_id: str) -> None:
def create_area(
self, study: Study, area_creation_info: AreaCreationDTO
) -> AreaInfoDTO:
area_id = transform_name_to_id(area_creation_info.name)
if area_id == "":
raise ValueError(
Copy link
Contributor

Choose a reason for hiding this comment

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

Si tu lèves une exception de type ValueError, cela va causer une erreur 500, ce qui ne serait pas très utile. Il serait préférable d'utiliser une exception spécifique comme ValidationError (de Pydantic), qui générerait une erreur 422. En général, il est préférable d'éviter d'utiliser des exceptions de la bibliothèque standard et plutôt utiliser une sous-classe de Exception. Pour les managers, nous avons pris l'habitude de lever des exceptions de type HTTPException. Étant donné que les managers ne sont utilisés que par les fonctions qui implémentent un endpoint, utiliser une sous-classe de HTTPException est tout à fait acceptable, donc nous pouvons partir là-dessus.

@@ -334,6 +334,11 @@ def remove_layer(self, study: RawStudy, layer_id: str) -> None:
def create_area(
self, study: Study, area_creation_info: AreaCreationDTO
) -> AreaInfoDTO:
area_id = transform_name_to_id(area_creation_info.name)
if area_id == "":
Copy link
Contributor

Choose a reason for hiding this comment

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

Je recommande if not area_id.

@@ -59,14 +59,21 @@ def _apply_config(
raise ValueError()

area_id = transform_name_to_id(self.area_name)

if area_id == "":
Copy link
Contributor

Choose a reason for hiding this comment

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

À remplacer par if not area_id

type=EventType.STUDY_DATA_EDITED,
payload=study.to_json_summary(),
permissions=PermissionInfo.from_study(study),
try:
Copy link
Contributor

Choose a reason for hiding this comment

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

Il n'est pas vraiment nécessaire d'utiliser un gestionnaire d'exception ici uniquement pour enregistrer un message d'erreur, car les exceptions non gérées sont déjà signalées lors de la gestion de l'erreur 500.

payload=study.to_json_summary(),
permissions=PermissionInfo.from_study(study),
try:
new_area = self.areas.create_area(study, area_creation_dto)
Copy link
Contributor

Choose a reason for hiding this comment

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

À mon avis, pour vérifier le format du nom de la zone, on pourrait utiliser une regex, par exemple :

class AreaCreationDTO(BaseModel):
    name: Field(regex=r"[\w(),&-][ \w(),&-]*")
    type: AreaType
    metadata: Optional[PatchArea]
    set: Optional[List[str]]

En procédant ainsi, la validation se ferra directement au niveau du end point.

@@ -241,6 +241,13 @@ def test_area_crud(
],
RequestParameters(DEFAULT_ADMIN_USER),
)
with pytest.raises(
ValueError,
Copy link
Contributor

Choose a reason for hiding this comment

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

Proposer une autre exception.

@commit-lint
Copy link

commit-lint bot commented May 26, 2023

Bug Fixes

  • commands: it is now impossible to create a study with an empty id (db6cf1f)

Contributors

MartinBelthle

Commit-Lint commands

You can trigger Commit-Lint actions by commenting on this PR:

  • @Commit-Lint merge patch will merge dependabot PR on "patch" versions (X.X.Y - Y change)
  • @Commit-Lint merge minor will merge dependabot PR on "minor" versions (X.Y.Y - Y change)
  • @Commit-Lint merge major will merge dependabot PR on "major" versions (Y.Y.Y - Y change)
  • @Commit-Lint merge disable will desactivate merge dependabot PR
  • @Commit-Lint review will approve dependabot PR
  • @Commit-Lint stop review will stop approve dependabot PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Creating an area with only weird characters breaks the front
3 participants