-
Notifications
You must be signed in to change notification settings - Fork 0
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
Fixes fmu properties update #234
Conversation
8caa133
to
ae2e01f
Compare
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.
Hmm, I wonder why All geometeries are updated when geojson changed and not just the changed one.
Maybe executing that query on ActiveRecord::Base in after_save running in not the same transaction. Maybe moving |
Also when using |
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.
I think I saw usage of properties
also in calculate_current
fmu_operator model. That needs to be removed as well.
29118c6
to
84b0065
Compare
One test is failing, otherwise looks good 👍 |
955f3b7
to
49daf31
Compare
UPDATE!! 09/07/2021:
Forget about those 2 branches that I was talking about yesterday!
I have discarded removing duplicated "properties". It was not going to work for the front end. Then properties is updated, then geojson[" properties"] is merged with properties updated.
I have changed the query in update_geometry to work only over the current fmu. I don't see any reason to go over all the fmus neither.
UPDATE END
UPDATE!! 08/07/2021:
I decide to split the code that was here into two different branches.
First one, this one:
spoiler: we don't need to sync the info at geojson.properties neither at geometry because we are not going to use it anymore
Removes properties from
def update_geometry
why? First of all because it was messing around mismatching properties.
As far as I understand, we are adding to the geometries information that is already present in the geojson column.
This info is duplicated in properties and some of the information also is reflected at its own column or directly accessible:
'id', 'fmu_name', 'iso3_fmu', 'company_na', 'operator_id', 'certification_fsc', 'certification_pefc', 'certification_olb', 'certification_pafc', 'certification_fsc_cw', 'certification_tlv', 'certification_ls', 'observations', 'fmu_type_label'
UPDATE END
Here I am trying to fixes the lack of sync between the information stored in the properties of some Fmus(forest management units).
fmu.rb
has_one :fmu_operator, ->{ where(current: true) }
has_one :operator, through: :fmu_operator
and its properties should look like this:
properties['company_na'] = operator&.name
properties['operator_id'] = operator&.id
I have added this task to spot "wrong" fmus and save them:
lib/tasks/fmus.rake
Saving the object triggers some clalbacks:
This one always updates geojson['properties'] so we will always call update_geometry:
before_validation :update_geojson
I have modified this one to ensure that the info in properties match the info in fmu_operator:
before_save :update_properties
And this one is a little motherfucker:
after_save :update_geometry, if: :geojson_changed?
Why?
I have discovered that after running rails fmu:current FOR_REAL=true the wrong fmus were fixed but 2 fmus that were OK get broken.
After a session of debugging I am 99% sure that nothing unexpected happens until, somehow, running update_geometry for the broken fmus brokes the properties for "some" fmus that are OK.
If this callback is removed or simply commenting the content of the method makes all the fixing work as expected and no other fmu is harmed in the process.
SO, my biggest doubt here is why do we use this query instead of a simple update_attributes approach? And how can this query affect to a different fmu?