Skip to content

1.1.9#368

Merged
henrihaapalasiili merged 5 commits intomasterfrom
1.1.9
Feb 24, 2026
Merged

1.1.9#368
henrihaapalasiili merged 5 commits intomasterfrom
1.1.9

Conversation

@henrihaapalasiili
Copy link
Copy Markdown
Contributor

No description provided.

HenryVisuri and others added 5 commits February 13, 2026 14:06
…eenpäin, kun elementtiä siirretään menneisyydestä (#362)

* KAAV-3492 Next elements not validated correctly when moving item from past to after current date fix

* Potential fix for pull request finding 'Modification of parameter with default'

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>

* Potential fix for pull request finding 'Variable defined multiple times'

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>

* Potential fix for pull request finding 'Unused local variable'

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>

* Potential fix for pull request finding 'Explicit returns mixed with implicit (fall through) returns'

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>

* Potential fix for pull request finding 'Unused local variable'

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>

* Potential fix for pull request finding 'Unused local variable'

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>

* speed up project validation preview: cache attribute metadata per validation request and feed it through
  update_attribute_data so fake PATCH flows stop re-querying Attributes
- add timing metrics around validation + deadline calculations to keep
  measuring latency regressions
- memoize preview deadline calculations so initial/update passes reuse
  results instead of recomputing the same dependency graph

* Restore on-hold timestamp and repair migration pytest kept crashing because the serializer/admin still toggle Project.onhold_at but the column no longer existed. Migration 0184 adds the field back while the model/admin/serializer changes keep behaviour consistent. That exposed migration 0166 importing the live Project model, which now included onhold_at and caused undefined-column errors on fresh DBs. Switching the data migration to use apps.get_model ties it to the historical schema so migrations (and tests) run cleanly.

* Potential fix for pull request finding 'Syntax error'

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>

* KAAV-3492 Return all date corrections in single validation pass

- Skip deadline validator for ?fake=true requests (section.py)
- Merge preview values into response for fake requests (project.py)
- Filter date errors for fake requests, let backend auto-correct
- Real saves unchanged: still validate and reject invalid dates

Eliminates cascading validation calls that caused 30s+ per round.

* KAAV-3492 fix onhold_at verbose_name for localisation

* Potential fix for pull request finding 'Explicit returns mixed with implicit (fall through) returns'

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>

* KAAV-3492: Optimize fake validation for timeline dates

- Add fast-path in views.py for ?fake=true PATCH requests that bypasses
  the full serializer and calls get_preview_deadlines() directly
- Skip expensive external API calls (kaavoitus_api, AD) for fake requests
  in project serializer
- Add payload_keys filter in section serializer to only validate
  attributes present in the request
- Fix syntax error in section.py (stray .select_related line)
- Add debug logging for fake validation flow (RECEIVED/CORRECTIONS/RETURNING)

Performance improvement: ~30s -> ~2s for timeline validation

* KAAV-3492: Optimize timetable validation for fake requests

- Only filter section attributes by payload keys when is_fake_request=True
  (preserves original behavior for normal requests and tests)
- Remove debug logging from project serializer and views
- Fast-path for fake validation returns corrected dates via get_preview_deadlines()

* get_preview_deadlines() now passes updated_attribute_data (all existing values + changes) instead of just updated_attributes (only changes)
Deadlines are preserved and only moved if they violate minimum distances

* fix: prevent saving during preview/validation mode

CRITICAL BUG FIX: _set_calculated_deadlines was calling self.save()
even when preview=True (validation mode), causing unintended data
saves. Now only saves when not in preview mode.

* fix: cascade deadline updates from ehdotus to tarkistettu_ehdotus

Removed line that was overwriting calculated values with old values
from preview_attribute_data, blocking the cascade chain.
Also removed debug logging.

* KAAV-3517: Fix confirmed fields not being protected during deadline recalculation (#365)

Backend changes:
- Fixed _set_calculated_deadline() to return the original confirmed value instead of the calculated value when a field is in confirmed_fields
- This prevents confirmed/locked dates from being overwritten during save

The bug was that when a field was in confirmed_fields, the code was returning the newly calculated date instead of the original saved date, causing confirmed dates to be recalculated on every save.

* KAAV-3492: Fix lautakunta deadline when esilläolo OFF

- Add _get_esillaolo_off_distance_override() for special case handling
- Calculate from phase start instead of esilläolo_paattyy when esilläolo is OFF
- Read distance values from DB (DeadlineDistance) instead of hardcoding
- Supports both periaatteet and luonnos phases

* KAAV-3492: Skip distance rules when conditions not met in validation

- Check distance.check_conditions() before applying min distance rules
- Prevents invalid distance enforcement when esilläolo groups are OFF

* KAAV-3428: Fix lautakunta dates not pushed when adding 3rd+ esillaolo

Added _get_latest_esillaolo_date() to find latest esillaolo variant.
Special handling in _enforce_distance_requirements() for P6/P7.
Fixed visibility boolean init in get_preview_deadlines().

* KAAV-3517: Fix selective deadline distance enforcement

- Only enforce distance requirements on deadlines that actually changed
  (compare incoming values vs database, not just what frontend sends)
- Only apply enforcement when minimum distance is actually violated
- Remove hacky filter condition that incorrectly excluded deadlines
- Prevents cascade effects where moving one deadline shifts unrelated dates
- Add comprehensive tests for the new selective enforcement logic

* fixed test

* removed non used stuff

* KAAV-3492: Fix phase bar expansion when deleting deadline groups

- Respect explicitly sent visibility booleans from frontend (False for deletion)
- Don't auto-enable secondary slots (_2, _3, _4) when primary (_1) is disabled
- Check stored visibility before auto-enabling existing deadlines
- Skip deadline validation for disabled deadline groups
- Refactor: rename 'date' to 'enforced_date' for clarity, use != instead of 'not =='
- Refactor: extract is_phase_boundary variable in deadline calculation

* KAAV-3492: Fix timeline cascade and lautakunta date snapping

- Add forward cascade in get_preview_deadlines() using distances_to_next
- Detect visibility bool False→True to trigger distance enforcement on re-add
- Snap dates to valid date_type in _enforce_distance_requirements()
  (ensures lautakunta dates always land on valid Tuesdays)
- Add test files for deadline lifecycle and data completeness

* KAAV-3492: Always snap deadlines to valid date_type in preview

Per AT2.5.1: Deadline must be a work day. Now all deadlines with
date_type are snapped via get_closest_valid_date(), not just those
needing distance enforcement. Fixes July dates not correcting to August.

* KAAV-3492 Iterates through all deadlines after phase boundaries are recalculated
Skips deadlines already processed or in the original cascade
Checks if any distances_to_previous rules are now violated
Enforces the minimum distance if violated (with log message [KAAV-3492 POST-CALC])

* KAAV-3492 Refactoring code to clear cache and include attribute enforcement in the convergence loop.
Removing isolated post-calc loop before integration.
Replacing convergence loop with integrated enforcement logic.

* KAAV-3492 adding logic fixes

* KAAV-3492 refactored code

* KAAV-3942 fix confirmed fields saving

* Potential fix for pull request finding 'Unused local variable'

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>

* removed unused variable

* KAAV-3492 reverted files not needed and modified gitignore

* removed non needed files

* removed settings.json from branch

* test for deadline lifecycle

* KAAV-3492 fix backend silently not updating correct changes from updated_attribute_data to response and possibly messing up some validations

* removed some faulty log infos

* Clean up unused imports and fix iteration variable bug

* modofied tests

* KAAV-3492 Fix in _set_calculated_deadline: Checks preview_attribute_data before using calculated values, preventing the convergence loop from overwriting enforced or user-provided values.
Missing preview_attribute_data parameter: Added the parameter to the first _set_calculated_deadlines call, ensuring preview data flows through the entire calculation chain.

* Fix auto-calculated deadlines using stale preview values

Skip preview values for deadlines with edit_privilege=None. Ensures
periaatteetvaihe_paattyy_pvm recalculates to match esillaolo_paattyy.

* KAAV-3492: Fix timeline cascade using minimum distances instead of initial distances

- Use distance_from_previous (minimum) instead of initial_distance for cascade calculations
- Prevent cross-phase cascade for non-boundary deadlines
- Fix phase prefix detection order (tarkistettu_ehdotus before ehdotus)
- Remove debug logging statements

* prevent backward date snap when addin
Change condition from > to < in get_preview_deadlines() so minimum
distances only enforce forward movement, not backward snapping.

* Initial positioning to be used when adding new elements and continuing with minium distance validation

* temp logging

* KAAV-3492 audit and cleanup command for possible stale data on project

* (KAAV-3492): Prevent stale deadline dates from being created

- Root cause: _set_calculated_deadline() wrote dates to attribute_data
  regardless of visibility bool value, causing stale data in all project
  sizes (not just XL)
- Added visibility bool check before writing dates to prevent creation
  of stale data when vis_bool=False
- Added clean_stale_deadline_fields() call in update_initial_data() to
  cleanup orphaned dates when XL project toggles are disabled
- Created shared deadline_utils.py module with DEADLINE_GROUP_DATE_FIELDS
  constant and utility functions for detection/cleanup
- Reduced code duplication in audit/cleanup management commands

* unused import remove

* - Add user_changed_fields param to _set_calculated_deadlines to skip
  recalculation for explicitly changed deadlines
- Exclude user-changed fields from update_dls_to_calc
- Update deadline_utils and serializer for fix support

* fixes

* Test to be more reliable

* test fixed for github

* removed useless tests

* fixes

* fix: exclude auto-calculated deadlines from actually_changed set

Phase boundaries (edit_privilege=None) now always recalculate when
inner deadlines cascade forward, per AT1.2.1/AT1.2.3.

* modified comments to be cleaner for the chanhes

* fix: phase boundaries recalculate after cascade; remove debug logging

- Exclude auto-calculated deadlines (edit_privilege=None) from
  actually_changed set so E9/T5 phase boundaries always recalculate
  when inner deadlines cascade forward (per AT1.2.1/AT1.2.3)
- Cache calculate_initial/calculate_updated querysets on Deadline
  instance to avoid repeated DB queries in convergence loop
- Remove all debug logging from project.py, serializers/project.py,
  section.py, and views.py

* sonar cloud suggestions

* Add timeline_save mode with raw preview validation

- Add timeline_save query param to skip cascade during validation
- New get_raw_deadline_preview() validates user's exact input
- Fix deadline distance lookup to check conditions (not just .first())
- Skip deadline recalculation in update_deadlines during save
- Process ALL phases during timeline_save validation

* tests added

* recalculate RE-ENABLED deadlines from predecessor

When a deadline group's visibility bool changes False→True, existing deadlines now recalculate from their predecessor using distances_to_previous instead of keeping stale dates. This fixes the lautakunta ehdotus 3 bug where E8.3 kept old date (2030-11-19) causing E4 to jump 300 days forward.

* re-enabling phases condition fix so they actually can be moved  after re-enabling

* removed unsused code

* prevent date recalculation during timeline_save

- Add timeline_save parameter to update_deadlines() to skip
  _set_calculated_deadlines() during save
- Accept ALL deadline attribute fields (including phase boundaries)
  in valid_attributes for timeline_save
- Fixes dates shifting unexpectedly when saving timeline

Per validation.md: Save Must NOT Recalculate Dates

* U1 date to sync with K1

---------

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
@sonarqubecloud
Copy link
Copy Markdown

@henrihaapalasiili henrihaapalasiili merged commit 1c36f53 into master Feb 24, 2026
23 of 28 checks passed
henrihaapalasiili added a commit that referenced this pull request Feb 26, 2026
Merge pull request #368 from City-of-Helsinki/1.1.9
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.

3 participants